HOME      BLOG       FORUMS      CONTACT       ABOUT

Lists all the drives present in Windows using java

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 "/"

Share

Tags: , , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply