比如,我的代码目前看起来像下面这样。当FileOutputStream
关闭时,我是否需要显式调用lock.release
或者它会自动释放?
var os:FileOutputStream = null
var writer:PrintWriter = null
try {
os = new FileOutputStream(name, false)
val lock = os.getChannel().tryLock
if(lock != null) {
writer = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(os)))
(write stuff to file)
} else {
(error stuff)
}
} finally {
if(writer != null) writer.close
os.close
}