Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners Listing the File System Roots

 
 

Share on Google+Share on Google+

Listing the File System Roots

Advertisement
In this section, you will learn to get all directories in your system.

Listing the File System Roots

     

In this example we will list out all the drives in the disk. This requires an array of File class where all the drives will get stored by using only one method.

listRoots(): It is the method of the File class. It lists the name of the drives.

 

Code of this example is given below:

 

 

import java.io.*;

public class ListSystemRoots {
  static File giveRoot[];

  public ListSystemRoots(){
  }
  public static void main(String args[]){
  giveRoot = File.listRoots();  // list the names of the drives
  for (int i = 0; i < giveRoot.length; i++)
  System.out.println(giveRoot[i]);  // Print the list
  }
}

output is given below:

C:\ListSystemRoots>java ListSystemRoots
A:\
C:\
D:\
E:\
F:\
G:\

Download this program

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 7, 2007

Related Tutorials

Discuss: Listing the File System Roots  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com