Force java to release all file locks / handles in Java

My java application (which is quite a lot of code) performs a lot of file operations In my application, I need to move files from one location to another, so I'm using files. In JDK7 Move method

When I try to do this, I receive an error telling me that the file is in use I know the fact that this is part of my code locking this resource

How do I force my java application to release all locks before calling the move / rename my file function?

If this is not possible, is there a simple way to check which part of my code locks the file? Finding unclosed file handles through my entire code base will be a nightmare, considering the amount of code

thank you

Solution

The file () object does not lock the file, but FileStream (FileInputStream / fileoutputstream) locks it So you must write a helper class (such as singleton) for your streams to record all streams

However, please note that if your code leaks, it is better to fix the error than close all files

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>