List Filesystem roots or drives in Java
Description
The following code shows how to list Filesystem roots or drives.
Example
/* w w w . ja v a 2 s . com*/
import java.io.File;
public class Main {
public static void main(String[] args) {
File[] rootDirectories = File.listRoots();
System.out.println("Available root directories:");
for (int i = 0; i < rootDirectories.length; i++) {
System.out.println(rootDirectories[i]);
}
}
}
The code above generates the following result.