Topic: 求教有关javaIO的问题,谢谢!

  Print this page

1.求教有关javaIO的问题,谢谢! Copy to clipboard
Posted by: welcomeriver
Posted on: 2005-03-17 15:04

import java.io.*;
import java.security.*;
import javax.crypto.*;

public class StreamIn
{
public static void main(String[] args) throws Exception
{
FileInputStream f = new FileInputStream("key1.dat");
ObjectInputStream b = new ObjectInputStreamRose;
Key k = (Key)b.readObject();

Cipher cp = Cipher.getInstance("DESede");
cp.init(Cipher.ENCRYPT_MODE, k);

FileInputStream in = new FileInputStream("test1.txt");
CipherInputStream cin = new CipherInputStream(in, cp);
int num = in.available();
byte ptext[] = new byte[num];
cin.read(ptext);

FileOutputStream out = new FileOutputStream("test2.txt");
Cipher cp1 = Cipher.getInstance("DESede");
cp1.init(Cipher.DECRYPT_MODE, k);
CipherOutputStream cout = new CipherOutputStream(out, cp1);

cout.write(ptext);

cout.close();
out.close();
in.close();
cin.close();
}
}

为什么输出文件 test2.txt 总是空的呢?

2.Re:求教有关javaIO的问题,谢谢! [Re: welcomeriver] Copy to clipboard
Posted by: welcomeriver
Posted on: 2005-03-17 15:06

怎么有朵花呢?!
那条语句为: ObjectInputStream b = new ObjectInputStream( f );


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923