<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Java 程序:重命名文件 > 原文: [https://www.programiz.com/java-programming/examples/rename-file](https://www.programiz.com/java-programming/examples/rename-file) #### 在本教程中,我們將學習使用 Java 重命名文件。 [Java `File`](/java-programming/file "Java File Class")類提供`renameTo()`方法來更改文件名。 如果重命名操作成功,則返回`true`,否則返回`false`。 * * * ### 示例:使用 Java 重命名文件 ```java import java.io.File; class Main { public static void main(String[] args) { // create a file object File file = new File("oldName"); // create a file try { file.createNewFile(); } catch(Exception e) { e.getStackTrace(); } // create an object that contains the new name of file File newFile = new File("newName"); // change the name of file boolean value = file.renameTo(newFile); if(value) { System.out.println("The name of the file is changed."); } else { System.out.println("The name cannot be changed."); } } } ``` 在上面的示例中,我們創建了一個名為`file`的文件對象。 該對象保存有關指定文件路徑的信息。 ```java File file = new File("oldName"); ``` 然后,我們使用指定的文件路徑創建一個新文件。 ```java // create a new file with the specified path file.createNewFile(); ``` 在這里,我們創建了另一個名為`newFile`的文件對象。 該對象保存有關指定文件路徑的信息。 ```java File newFile = new File("newFile"); ``` 要更改文件名,我們使用了`renameTo()`方法。`newFile`對象指定的名稱用于重命名`file`對象指定的文件。 ```java file.renameTo(newFile); ``` **如果操作成功**,則顯示以下消息。 ```java The name of the file is changed. ``` **如果操作不成功**,則會顯示以下消息。 ```java The name cannot be changed. ```
                  <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>

                              哎呀哎呀视频在线观看