The JVM occupies a file that causes the file not to be deleted, and attempting to manually delete the file during debug will prompt "The file has been opened in Java platform se binary."
Generally speaking, there are several reasons for Java File.delete failure
1. See if it is referenced by another process, delete it manually (delete is occupied by another process)
2.file is a folder and is not empty, a different folder or file,
3. There is a high likelihood that the flow of this file will not be closed before itself
Reproduced from: https://www.cnblogs.com/stono/p/6736767.html
But after I added the file flow shutdown statement, I still didn't solve my problem. Speculation may be the way the flow closed, only to think that should be in the closed flow in finally to be reliable, to find books found in the book is not very good, and then found in the try to close the file flow in the correct posture. (Thank you: https://blog.csdn.net/qq_27093465/article/details/52439754) The stream is declared in a try, initialized in a try, and then in finally to close, Remember to handle the exception e,finally inside close and try a catch again.
private static void Testclosefilestream () {final Logger LOG = Loggerfactory.getlogge
R (Cmshome.class);
String fileName = "";
InputStream InputStream = null;//declares a reference because the new object is also an exception to try {///here, if the filename does not exist.
InputStream = new FileInputStream (fileName);
catch (IOException e) {///This is mainly to show the exception to see, or even if abnormal, see can not find the problem.
Log.debug ("Loadproperties ioexception:" + e.getmessage ()); finally {if (InputStream!= null) {try {inputstream.close ();//Close Stream} catch (IOException e) {log.debug ("InputStream close IOException:" + E.getmessag
E ()); }
}
}
}
}