OStream无法关闭,用的是Eclipse 2020
package IOStream_package;
import java.io.*;
public class ReadAndWrite {
public static void main(String[] args) {
InputStream istream;
OutputStream ostream;
File outputFile = new File("E:\\java\\file\\ReadWrite");
int c;
final int EOF = -1;
istream = System.in;
ostream = System.out;
try {
ostream = new FileOutputStream(outputFile);
System.out.println("Type some characters ");
try {
while((c = istream.read())!=EOF)
ostream.write(c);
}catch(IOException e){
System.out.println("Error:"+e.getMessage());
}
finally {
try {
istream.close();
ostream.close();
System.out.println("File closed.");
}catch(IOException e) {
System.out.println("File did not close.");
}
}
}catch(FileNotFoundException e) {
System.exit(1);
}
}
}
交换过istream.close()和ostream.close()的位置,结果istream.close也无法执行。
ostream和istream都同时关闭
ostream是System.out,这两个不用关闭吧