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 you will not be able to close the stream of this file before yourself (the situation I encountered)
This method I used to get the size of the file, used the stream class, but ran out without shutting down, causing the file could not be deleted:
public string GetFileSize (string path,string filename) throws IOException {
String pathstring=path+ "\" +filename;
F=new File (pathstring);
FileInputStream fis=new FileInputStream (f);
String time=string.valueof ((double) fis.available ()/1024));
Fis.close ();//There was no shutdown.
Return time.substring (0, Time.indexof (".") +2) + "K";
}
Personally think: First, manually, that is, the computer found to delete the file to see if you can delete, if the deletion does not drop, (personal encounter is also the use of the file's input and output stream is not closed.) )
Check the input and output stream of your code to see if the power is used but not closed.