所以当然我们必须 try-catch-finaly 任何可关闭的资源。
但是我遇到了一些代码,这些代码如下:
java.util.Properties myProps = ... reads & loads (and doesn't close Stream!)
myProperties.store(new FileOutputStream(myFilePath), null);
System.exit(0);
java.util.Properties.store()
刷新底层流 (the FileOutputStream
) 这足够了吗?你能想到文件不会被写入的场景吗?假设方法通过并且在“存储”中没有抛出异常