File.createNewFile() randomly fails

前端 未结 3 746
谎友^
谎友^ 2021-01-25 14:06

I\'ve build a simple test which creates and deletes a file (name does not change) in an infinite loop. The test does run for a couple of seconds (sometimes over 77,000 iteration

3条回答
  •  借酒劲吻你
    2021-01-25 14:25

    This issue reminds me a problem I experienced recently with the File.renameTo() method. It is (was?) due to this bug in the jvm :

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213298

    A weird workaround is to call System.gc() and to retry renaming the file again (and it works...).

    Not sure it has a link with your issue, but it may be worth exploring...

提交回复
热议问题