<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Java – 刪除臨時文件 > 原文: [https://howtodoinjava.com/java/io/how-to-delete-temporary-file-in-java/](https://howtodoinjava.com/java/io/how-to-delete-temporary-file-in-java/) 如果您的應用程序需要為某些應用程序邏輯或單元測試創??建臨時文件,那么您要確保在不需要這些臨時文件時將其刪除。 讓我們學習**如何在 Java** 中刪除臨時文件。 ## 使用 `File.deleteOnExit()`或`File.delete()`刪除臨時文件 要在存在復制或完成復制時刪除文件,可以使用: ```java File temp = File.createTempFile("myTempFile", ".txt"); temp.deleteOnExit(); ``` 要刪除文件,可以立即使用`delete()`方法,而無需等待應用程序退出。 ```java File temp = File.createTempFile("myTempFile", ".txt"); temp.delete(); ``` #### 刪除臨時文件的示例代碼 ```java import java.io.File; import java.io.IOException; public class TemporaryFileExample { public static void main(String[] args) { File temp; try { temp = File.createTempFile("myTempFile", ".txt"); System.out.println("Temp file created : " + temp.getAbsolutePath()); //temp.delete(); //For deleting immediately temp.deleteOnExit(); //Delete on runtime exit System.out.println("Temp file exists : " + temp.exists()); } catch (IOException e) { e.printStackTrace(); } } } ``` ## 使用 NIO 將數據寫入臨時文件 如果要使用 Java NIO 庫,則可以使用`Files.delete()`或`Files.deleteIfExists()`方法。 ```java public class TemporaryFileExample { public static void main(String[] args) { try { final Path path = Files.createTempFile("myTempFile", ".txt"); System.out.println("Temp file : " + path); //Delete file on exit Files.deleteIfExists(path); //Delete file immediately Files.delete(path); } catch (IOException e) { e.printStackTrace(); } } } ``` **祝您學習愉快!**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看