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.