How do I get the list of file system root?
Category: java.io, viewed: 2K time(s).
The code below demonstrate how to obtain file system root available on your operating system. In Linux you'll have a single root "/" while on Windows you could get C:\ or D:\ that represent the root of the C and D drives.
package org.kodejava.example.io;
import java.io.File;
public class FileSystemRoot {
public static void main(String[] args) {
//
// List the available filesystem roots.
//
File[] root = File.listRoots();
//
// Iterate the entire filesystem roots.
//
for (int i = 0; i < root.length; i++) {
File file = root[i];
System.out.println("Root: " + file.getAbsolutePath());
}
}
}