Listing a file system's root directories
Fri Apr 28, 2017 · 77 words

Using the static FileSystems class, you can get the default FileSystem (note the missing s) through the getDefault() method.

The getRootDirectories() method of FileSystem can be used to acquire a list of root directories on a file system.

An object of type Iterable is returned, so the directories can be iterated over in the following way:

FileSystem sys = FileSystems.getDefault();
Iterable<Path> d = sys.getRootDirectories();
for (Path name: d) {
    System.out.println(name);
}

This is available from Java 1.7.


back · he thought · he could · so he did · main