File.listRoots() will list out all the available file system roots / drives in your current system.

Example

package com.mkyong.io;
 
import java.io.File;
 
public class App{
 
   public static void main (String args[]) {
 
	   File[] rootDrive = File.listRoots();
 
	   for(File sysDrive : rootDrive){
		   System.out.println("Drive : " + sysDrive);
	   } 
   }
}

Output

Drive : A:\
Drive : C:\
Drive : D:\
Drive : E:\
This article was posted in Java category.