Home >Java >javaTutorial >What to do if the java file cannot be deleted
What should I do if the java file cannot be deleted?
Solution to using Java file to delete file.delete() that cannot delete a file
Today, when using springboot to delete a file, it cannot be deleted normally. After a period of investigation, we found that the problem was caused by not closing the data stream after reading the file, so we recorded it again.
Recommended tutorial: "java learning"
Find the reason
The file cannot be deleted. Generally, the file is occupied by a certain program process. In the code It is very likely that the stream operation was not closed after the data flow operation was completed. If it is a DB file, it is also possible that the DB operation was not closed. Search carefully.
Solution
Find the stream or DB file operation that is not closed, add a closing statement, and then execute the file.delete() operation.
The above is the detailed content of What to do if the java file cannot be deleted. For more information, please follow other related articles on the PHP Chinese website!