...  System.out.printf("Absolute path: %s%n", path.toAbsolutePath());
31
32            if (Files.isDirectory(path)) { // output directory listing
33               System.out.printf("%nDirectory contents:%n");
34
35               // object for iterating through a directory's contents
36               DirectoryStream<Path> directoryStream =
37                  Files.newDirectoryStream(path);
38
39               for (Path p : directoryStream) {
40                  System.out.println(p);
41               }
42            }
43         }
44         else { // not file or directory, output error message
45            System.out.printf("%s does not exist%n", path);
46         }
47      } // end main
48   } // end class FileAndDirectoryInfo
Enter file or directory name:
c:\examples\ch15 ch15 exists Is a directory Is an absolute path Last modified: 2013-11-08T19:50:00.838256Z Size: 4096 Path: c:\examples\ch15 Absolute path: ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.