ADS

List All Local Drives In Java

An example on getting paths of all local drives in a computer in Java.

Get Local Drive Paths - Example


 import java.io.File;
class GetLocalDrives
{
public static void main(String args[])
{
File[] f=File.listRoots();
for(File k:f)
System.out.println(k);
}
}


listRoots(): It is a static method of the java.io.File class and is used to get all the roots (local drives).


Sample Output


 C:\
D:\
E:\
F:\
G:\

Subscribe to receive free email updates:

ADS