Home Tutorial Java Core Files How to list all drives available in the system

 
 

Share on Google+Share on Google+
How to list all drives available in the system
Posted on: April 3, 2006 at 12:00 AM
Advertisement
In this section, you will learn how to list out all the drives available in the system.

How to list all drives available in the system

In this section, you will learn how to list out all the drives available in the system. 

Description of code:

To get the list of drives, we have called the method listRoots() of File class. This will return an array of File objects for the drives that are available in the system.

Here is the code:

import java.io.*;

class ListDrives {
  public static void main(String[] args) {
    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
      System.out.println("Drive:" + roots[i]);
    }
  }
}

Above code will print all the drives available in the system. With the help of above code you can find the drives attached to your system.

Advertisement

Related Tags for How to list all drives available in the system:


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: April 3, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com