In Java we can use listRoots() of File class to find all root directories.
import java.io.*; public class Lazyroar { public static void main(String[] args) { File[] rDirs = File.listRoots(); for ( int i = 0 ; i < rDirs.length; i++) System.out.println(rDirs[i].toString()); } } |
Output (In Windows with two drives)
C:\ D:\
Output (In Linux)
/