我是否必须关闭由 PrintStream 包装的 FileOutputStream?
我用这个:FileOutputStream
PrintStream
class PrintStreamDemo {
public static void main(String args[]) {
FileOutputStream out;
PrintStream ps; // declare a print stream object
try {
// Create a new file output stream
out = new FileOutputStream("myfile.txt");
// Connect print stream to the output stream
ps = new PrintStream(out);
ps.println ("This data is written to a file:");
System.err.println ("Write successfully");
ps.close();
}
catch (Exception e) {
System.err.println ("Error in writing to file");
}
}
}
我只关闭 .我是否还需要关闭 ()?PrintStream
FileOutputStream
out.close();