文件這是我的代碼:如何關閉Java中
FileWriter fw = new FileWriter(log,true);
BufferedWriter bw = new BufferedWriter(fw);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
fw.close();
bw.close();
sw.close();
pw.close();
我想改變它的東西是這樣的:
BufferedWriter bw = new BufferedWriter(new FileWriter(log,true));
PrintWriter pw = new PrintWriter(new StringWriter());
bw.close();
pw.close();
請問這是正確的,否則將丟失的close()
電話導致問題?
從'PrintWriter#close'文檔:'關閉流並釋放與其關聯的任何系統資源。關閉以前關閉的流不起作用。' – SomeJavaGuy