Wednesday, November 20, 2024
Google search engine
HomeLanguagesJavaJava | Print root directories

Java | Print root directories

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)

/
RELATED ARTICLES

Most Popular

Recent Comments