This question arose when I came across the same doubts.
Not finding the absolute answer, I checked several tests.
I can confirm that yes, just closing the writer will release the locks. You do not even need to manually close the stream that is under the writer.
As I tested:
1) I run the code in Eclipse in debug mode. 2) After writing and cleaning the file (before closing), I tried to delete the file using Windows Explorer. As expected, this was due to blocking. 3) As soon as I went through the writer.close () method, but before completing the execution, I again tried to delete the file. He deleted it without a problem.
This clearly tells me that the close () method will cause locks to be released.
NOTE. The above applies only to the JDK file class. Libraries that extend java.io.File can behave differently. For example, if you use the iSeries IfsJavaFile, you will have a connection memory leak if you also do not release the connection object to the iSeries server.
source share