小编Tor*_*arn的帖子

如果未调用System.gc(),File.delete()不会删除新文件

我目前在删除我从未在程序中使用的文件时遇到问题.

首先,这是我的配置:

  • java版本:1.8.0_20
  • os:Windows 7 Pro SP1

代码如下:

 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()的情况下解决此问题?

谢谢你提前

java file

6
推荐指数
1
解决办法
428
查看次数

离线 Firefox 性能工具

我在安全企业网络上开发的 Web 应用程序存在一些性能问题。互联网连接不可用。从某些版本的 Firefox 开始,性能工具会将我发送到类似“https://profiler.firefox.com/from-browser”的内容,当然,这是无法访问的。

如何在没有互联网连接的情况下分析性能问题?(离线工具还是 Firefox 性能工具的替代品?)

firefox performance-testing firefox-developer-tools

5
推荐指数
0
解决办法
255
查看次数