import java.io.*;
import java.nio.file.*;
US>class Test {
public static void main(String[]args) rows IOException {
Path p1 = Paths.get("C:\\gold\\.");
p1 = p1.resolve("dir1");
Path p2 = Paths.get ("C:\\gold");
p2 = p2.resolve("\\dir2");
System.out.print(p1+":");
System.out.print(p2);
}
}
Variable p2 is output to :C:\dir2 " but is an argument for the resolve method
"\dir2" is not an absolute path.
In my opinion, the output of variable p2 should be "C:\gold\dir2", but what is my understanding
Please let me know if it's wrong.
java windows
https://msdn.microsoft.com/ja-jp/library/windows/desktop/aa365247(v=vs.85).aspx#paths
According to the description in ,
\\
(two backslashes) starting with (UNC path)C:\
, d:\
, and so on, starting with a drive letter and slash
(starting with a single backslash) is the absolute path, so \dir2
is the absolute path.
Below is the original text
Fully Qualified vs. Relative Paths
For Windows API functions that manage files, file names can be relevant to the current directory, while some APIs require a fully qualified path.A file name is relative to the current directory if does not begin with one of the following:
© 2024 OneMinuteCode. All rights reserved.