Lists all the drives present in Windows using java
The listRoots method of File class is used for finding out all the drives available in Windows.
import java.io.File;
/**
* File class examples.
*
*/
public class FileExample {
public static void main(String[] args){
// Get all the drives
File drives[] = File.listRoots();
// Loop through the drive list and display the drives.
for (int index = 0; index < drives.length; index++) {
System.out.println(drives[index]);
}
}
}
Note: Since Linux does not have any drives concept, the output of the above program in Linux operating system will be "/"





















