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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### [**Paths**的增減修改](https://lingcoder.gitee.io/onjava8/#/book/17-Files?id=paths%e7%9a%84%e5%a2%9e%e5%87%8f%e4%bf%ae%e6%94%b9) 我們必須能通過對**Path**對象增加或者刪除一部分來構造一個新的**Path**對象。我們使用**relativize()**移除**Path**的根路徑,使用**resolve()**添加**Path**的尾路徑(不一定是“可發現”的名稱)。 對于下面代碼中的示例,我使用**relativize()**方法從所有的輸出中移除根路徑,部分原因是為了示范,部分原因是為了簡化輸出結果,這說明你可以使用該方法將絕對路徑轉為相對路徑。 這個版本的代碼中包含**id**,以便于跟蹤輸出結果: ~~~ // files/AddAndSubtractPaths.java import java.nio.file.*; import java.io.IOException; public class AddAndSubtractPaths { static Path base = Paths.get("..", "..", "..").toAbsolutePath().normalize(); static void show(int id, Path result) { if(result.isAbsolute()) System.out.println("(" + id + ")r " + base.relativize(result)); else System.out.println("(" + id + ") " + result); try { System.out.println("RealPath: " + result.toRealPath()); } catch(IOException e) { System.out.println(e); } } public static void main(String[] args) { System.out.println(System.getProperty("os.name")); System.out.println(base); Path p = Paths.get("AddAndSubtractPaths.java").toAbsolutePath(); show(1, p); Path convoluted = p.getParent().getParent() .resolve("strings").resolve("..") .resolve(p.getParent().getFileName()); show(2, convoluted); show(3, convoluted.normalize()); Path p2 = Paths.get("..", ".."); show(4, p2); show(5, p2.normalize()); show(6, p2.toAbsolutePath().normalize()); Path p3 = Paths.get(".").toAbsolutePath(); Path p4 = p3.resolve(p2); show(7, p4); show(8, p4.normalize()); Path p5 = Paths.get("").toAbsolutePath(); show(9, p5); show(10, p5.resolveSibling("strings")); show(11, Paths.get("nonexistent")); } } /* 輸出: Windows 10 C:\Users\Bruce\Documents\GitHub (1)r onjava\ ExtractedExamples\files\AddAndSubtractPaths.java RealPath: C:\Users\Bruce\Documents\GitHub\onjava\ ExtractedExamples\files\AddAndSubtractPaths.java (2)r on-java\ExtractedExamples\strings\..\files RealPath: C:\Users\Bruce\Documents\GitHub\onjava\ ExtractedExamples\files (3)r on-java\ExtractedExamples\files RealPath: C:\Users\Bruce\Documents\GitHub\onjava\ ExtractedExamples\files (4) ..\.. RealPath: C:\Users\Bruce\Documents\GitHub\on-java (5) ..\.. RealPath: C:\Users\Bruce\Documents\GitHub\on-java (6)r on-java RealPath: C:\Users\Bruce\Documents\GitHub\on-java (7)r on-java\ExtractedExamples\files\.\..\.. RealPath: C:\Users\Bruce\Documents\GitHub\on-java (8)r on-java RealPath: C:\Users\Bruce\Documents\GitHub\on-java (9)r on-java\ExtractedExamples\files RealPath: C:\Users\Bruce\Documents\GitHub\onjava\ ExtractedExamples\files (10)r on-java\ExtractedExamples\strings RealPath: C:\Users\Bruce\Documents\GitHub\onjava\ ExtractedExamples\strings (11) nonexistent java.nio.file.NoSuchFileException: C:\Users\Bruce\Documents\GitHub\onjava\ ExtractedExamples\files\nonexistent */ ~~~ 我還為**toRealPath()**添加了更多的測試,這是為了擴展和規則化,防止路徑不存在時拋出運行時異常。
                  <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>

                              哎呀哎呀视频在线观看