I currently encounter a problem deleting a file that I never use in my program.
First, here is my config :
- java version : 1.8.0_20
- os : Windows 7 Pro SP1
The code is as follow :
File out = new File(workingDirectory, filePrefix + "download");
// cleanup old failed runs
//System.gc(); // Bad! but seems the only way to pass the test
boolean isDeleted = out.delete();
assertTrue("Couldn't clear output location ("
+ " isDeleted="+isDeleted
+ " exists="+out.exists()
+ " canWrite="+out.canWrite()
+ ")", !out.exists());
The output error trace is :
junit.framework.AssertionFailedError:
Couldn't clear output location (isDeleted=false exists=true canWrite=true)
at [...]
This error is solved if I uncomment System.gc() which, in my opinion, is bad. It seems like Windows is holding some resources on the file even if it is never used.
My question is :
How can I solve this problem without using System.gc() ?
Thanks by advance