这是一个代码:
import java.io.*;
public class FileCharCopier
{
public static void main(String args[]) throws IOException
{
File f1=new File("scjp.txt");
File f2=new File("scjpcopy.txt");
FileReader in=new FileReader(f1);
FileWriter out=new FileWriter(f2);
int c;
while((c=in.read())!=1)
{
out.write(c);
in.close();
out.flush();
out.close();
}
}
}
我在同一个目录中有 scjp 和 scjpcopy.txt
但是当我运行程序时,我得到了这些错误:
java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at FileCharCopier.main(FileCharCopier.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
第 18 行是指
out.write(c);
有人可以纠正错误吗?