MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / PathInfo

Class PathInfo

files/PathInfo.java:10–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.io.IOException;
9
10public class PathInfo {
11 static void show(String id, Object p) {
12 System.out.println(id + ": " + p);
13 }
14 static void info(Path p) {
15 show("toString", p);
16 show("Exists", Files.exists(p));
17 show("RegularFile", Files.isRegularFile(p));
18 show("Directory", Files.isDirectory(p));
19 show("Absolute", p.isAbsolute());
20 show("FileName", p.getFileName());
21 show("Parent", p.getParent());
22 show("Root", p.getRoot());
23 System.out.println("******************");
24 }
25 public static void main(String[] args) {
26 System.out.println(System.getProperty("os.name"));
27 info(Paths.get(
28 "C:", "path", "to", "nowhere", "NoFile.txt"));
29 Path p = Paths.get("PathInfo.java");
30 info(p);
31 Path ap = p.toAbsolutePath();
32 info(ap);
33 info(ap.getParent());
34 try {
35 info(p.toRealPath());
36 } catch(IOException e) {
37 System.out.println(e);
38 }
39 URI u = p.toUri();
40 System.out.println("URI: " + u);
41 Path puri = Paths.get(u);
42 System.out.println(Files.exists(puri));
43 File f = ap.toFile(); // Don't be fooled
44 }
45}
46/* Output:
47Windows 8.1
48toString: C:\path\to\nowhere\NoFile.txt

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected