Get root directories with FileSystem in Java
Description
The following code shows how to get root directories with FileSystem.
Example
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.spi.FileSystemProvider;
//w ww .j a va2 s.c o m
public class Main {
public static void main(String[] args) {
FileSystem fileSystem = FileSystems.getDefault();
FileSystemProvider provider = fileSystem.provider();
Iterable<Path> rootDirectories = fileSystem.getRootDirectories();
System.out.println("Root Directories");
for (Path path : rootDirectories) {
System.out.println(path);
}
}
}
The code above generates the following result.