Java Reference
In-Depth Information
Path p1 = Paths.get("C:\\poems");
Path p2 = Paths.get("luci1.txt");
System.out.println(p1.resolve(p2));
Path p3 = Paths.get("C:\\test.txt");
System.out.println(p1.resolve(p3));
Path p4 = Paths.get("");
System.out.println(p1.resolve(p4));
Path p5 = Paths.get("poems\\Luci");
Path p6 = Paths.get("luci4.txt");
System.out.println(p5.resolve(p6));
C:\poems\luci1.txt
C:\test.txt
C:\poems
poems\Luci\luci4.txt
Relativizing is the process of getting a relative path for a given path against another path. The relativize(Path p)
method of the Path interface does this job. The relative path that is returned from this method, when resolved against
the same path against which the path was relativized, returns the same given path. A relative path cannot be obtained
if one of the paths has a root element. Whether a relative path can be obtained is platform-dependent if both paths
have root elements. The following snippet of code has some examples of getting relative paths. When there is no
common sub-path between the two paths, it is assumed that both paths locate sibling objects. For example, when
getting a relative path for Doug against Bobby , it is assumed that Doug and Bobby are siblings. The output is shown
when the program was run on Windows. On other platforms, you may get a slightly different output.
Path p1 = Paths.get("poems");
Path p2 = Paths.get("poems", "recent", "Luci");
System.out.println(p1.relativize(p2));
System.out.println(p2.relativize(p1));
Path p3 = Paths.get("Doug");
Path p4 = Paths.get("Bobby");
System.out.println(p3.relativize(p4));
System.out.println(p4.relativize(p3));
recent\Luci
..\..
..\Bobby
..\Doug
Symbolic Links
A symbolic link is a special type of file that contains a reference to another file or directory. A symbolic link is also
known as symlink or soft link . The file referenced by a symbolic link is known as the target file for the symbolic
link. Some operating systems that support symbolic links are UNIX-like operating systems (Linux, Mac OS X, etc.),
Windows Vista, Windows 7, etc.
 
Search WWH ::




Custom Search