Java | Print root directories Last Updated : 24 Mar, 2018 Improve Improve Like Article Like Save Share Report In Java we can use listRoots() of File class to find all root directories. import java.io.*; public class GeeksforGeeks { 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) / Like Article Suggest improvement Previous Traversing directory in Java using BFS Next Obtain List of Directories in R Share your thoughts in the comments Add Your Comment Please Login to comment...