我目前在删除我从未在程序中使用的文件时遇到问题.
首先,这是我的配置:
代码如下:
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());
Run Code Online (Sandbox Code Playgroud)
输出错误跟踪是:
junit.framework.AssertionFailedError:
Couldn't clear output location (isDeleted=false exists=true canWrite=true)
at [...]
Run Code Online (Sandbox Code Playgroud)
如果我取消注释System.gc(),我认为这是错误的,这个错误就解决了.看起来Windows即使从未使用过,也会在文件上保留一些资源.
我的问题是:
如何在不使用System.gc()的情况下解决此问题?
谢谢你提前
| 归档时间: |
|
| 查看次数: |
428 次 |
| 最近记录: |