我有以下代码,但是当我检查输出文件时,char[] cc 似乎没有被写入。有人可以告诉我有什么问题吗?
import java.io.*;
class Test {
public static void main(String[] args) {
System.out.printf("start of main\n");
char[] cc = new char[300];
try {
String s = "this is a test.";
System.arraycopy(s.toCharArray(), 0, cc, 0, s.length());
System.out.printf("cc = %s\n", new String(cc));
String filename = "tst.data";
DataOutputStream ostream = new DataOutputStream(new FileOutputStream(filename));
OutputStreamWriter writer = new OutputStreamWriter(ostream);
writer.write(cc, 0, 300);
ostream.close();
DataInputStream istream = new DataInputStream(new FileInputStream(filename));
InputStreamReader reader = new InputStreamReader(istream);
char[] newcc = new char[300];
reader.read(newcc, 0, 300);
istream.close();
System.out.printf("newcc = %s\n", new String(newcc));
} catch (Exception e) {
System.out.printf("Exception - %s\n", e);
}
}
}