How To Get Operating System Drive Letters in Java

This example shows how to list the system drive letters using Java program. File.listRoots() method returns the drive letter from the file system. Lets look at the simple example for listing the operating system’s drive letters for windows.



 * Find all drive letters in Java Example
 * @author Krishna
public class ListOSDrivesExample {

	public static void main(String[] args) {
		File[] roots = File.listRoots();

		   for(File localDrive : roots){
			   System.out.println("System Drive : " + localDrive);



System Drive : C:\
System Drive : D:\
System Drive : Q:\

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!