Fix: really delete file
This commit is contained in:
@@ -376,4 +376,25 @@ public class Utils {
|
||||
|
||||
return String.format("%.2f%s", (bytes / divider), suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes on Windows, delete of file return false for no obvious reason.
|
||||
* Wait a bit and try again
|
||||
*/
|
||||
public static boolean deleteFile(File file) {
|
||||
if (file.delete() == false) {
|
||||
// maybe the system was busy
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
}
|
||||
System.gc();
|
||||
if (file.delete() == false) {
|
||||
file.deleteOnExit(); // nothing more can be done...
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user