Java IO Tutorial

How to list out all system drives in your system

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:\

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Alarm Sistemleri
12 years ago

Your writing is very useful, thank you very much.