jdk7可以用 thy-with-resoucese, 不用手動關閉
查詢資料都說要實現autoclouseable接口才能自動關閉流 ,但自測了多次,不管是否測試aoutocloeseable中的close()方法都可以自動關閉

try( BufferedWriter write= new BufferedWriter(new FileWriter("E:\\testAutoCloseable.txt"))){ write.write("自動關閉"); System.out.println(1111); } catch (IOException e) { e.printStackTrace(); }