• <tfoot id='0ME0j'></tfoot>
  • <i id='0ME0j'><tr id='0ME0j'><dt id='0ME0j'><q id='0ME0j'><span id='0ME0j'><b id='0ME0j'><form id='0ME0j'><ins id='0ME0j'></ins><ul id='0ME0j'></ul><sub id='0ME0j'></sub></form><legend id='0ME0j'></legend><bdo id='0ME0j'><pre id='0ME0j'><center id='0ME0j'></center></pre></bdo></b><th id='0ME0j'></th></span></q></dt></tr></i><div id='0ME0j'><tfoot id='0ME0j'></tfoot><dl id='0ME0j'><fieldset id='0ME0j'></fieldset></dl></div>
      • <bdo id='0ME0j'></bdo><ul id='0ME0j'></ul>
    1. <legend id='0ME0j'><style id='0ME0j'><dir id='0ME0j'><q id='0ME0j'></q></dir></style></legend>

      <small id='0ME0j'></small><noframes id='0ME0j'>

        什么时候删除 Java 临时文件?

        时间:2023-07-12
        <i id='8Ik1U'><tr id='8Ik1U'><dt id='8Ik1U'><q id='8Ik1U'><span id='8Ik1U'><b id='8Ik1U'><form id='8Ik1U'><ins id='8Ik1U'></ins><ul id='8Ik1U'></ul><sub id='8Ik1U'></sub></form><legend id='8Ik1U'></legend><bdo id='8Ik1U'><pre id='8Ik1U'><center id='8Ik1U'></center></pre></bdo></b><th id='8Ik1U'></th></span></q></dt></tr></i><div id='8Ik1U'><tfoot id='8Ik1U'></tfoot><dl id='8Ik1U'><fieldset id='8Ik1U'></fieldset></dl></div>

            <tbody id='8Ik1U'></tbody>
        1. <legend id='8Ik1U'><style id='8Ik1U'><dir id='8Ik1U'><q id='8Ik1U'></q></dir></style></legend>
          <tfoot id='8Ik1U'></tfoot>
        2. <small id='8Ik1U'></small><noframes id='8Ik1U'>

              <bdo id='8Ik1U'></bdo><ul id='8Ik1U'></ul>
                • 本文介绍了什么时候删除 Java 临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我用 Java 方法创建了一个临时文件

                  Suppose I create a temporary file in Java with the method

                  File tmp = File.createTempFile(prefix, suffix);
                  

                  如果我没有显式调用 delete() 方法,文件什么时候会被删除?

                  If I do not explicity call the delete() method, when will the file be deleted?

                  作为一种直觉,它可能是在 JVM 终止时,或 较早(由垃圾收集器)或 较晚(由某些操作系统清理进程).

                  As an intuition, it might be when the JVM terminates, or earlier (by the Garbage Collector), or later (by some Operating System sweeping process).

                  推荐答案

                  文件不会被自动删除,从 JavaDoc:

                  The file won't be deleted automatically, from the JavaDoc:

                  此方法仅提供临时文件功能的一部分.到安排自动删除由此方法创建的文件,使用 deleteOnExit() 方法.

                  This method provides only part of a temporary-file facility. To arrange for a file created by this method to be deleted automatically, use the deleteOnExit() method.

                  所以你必须明确调用 deleteOnExit():

                  So you have to explicitly call deleteOnExit():

                  请求此抽象路径名表示的文件或目录虚拟机终止时被删除.

                  Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

                  这篇关于什么时候删除 Java 临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:运行 JVM 的 GC 参数是什么? 下一篇:何时以及如何将 java 类加载器标记为垃圾收集?

                  相关文章

                • <tfoot id='RpySS'></tfoot>
                  <i id='RpySS'><tr id='RpySS'><dt id='RpySS'><q id='RpySS'><span id='RpySS'><b id='RpySS'><form id='RpySS'><ins id='RpySS'></ins><ul id='RpySS'></ul><sub id='RpySS'></sub></form><legend id='RpySS'></legend><bdo id='RpySS'><pre id='RpySS'><center id='RpySS'></center></pre></bdo></b><th id='RpySS'></th></span></q></dt></tr></i><div id='RpySS'><tfoot id='RpySS'></tfoot><dl id='RpySS'><fieldset id='RpySS'></fieldset></dl></div>

                  <small id='RpySS'></small><noframes id='RpySS'>

                    • <bdo id='RpySS'></bdo><ul id='RpySS'></ul>
                      <legend id='RpySS'><style id='RpySS'><dir id='RpySS'><q id='RpySS'></q></dir></style></legend>