Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
Jul 14, 1999



Application Security Testing: An Integral Part of DevOps

Returning the Root Drives

Can you tell me how to get the root drives on a system?

The 1.0 and 1.1 version of the Java APIs did not include a means of determining the root drives or partitions on a system. During the development of the Swing APIs, it became clear such a function was needed to be able to implement the FileChooser class. Such a feature became available with the Swing 1.1 API in the javax.swing.filechooser.FileSystemViewclass, which had a getRoots() method that returned an array of File instances corresponding to the root drives or partitions. With the release of the Java 2 Platform, this functionality was moved into the File class in the form of a static getRoots() method. The following simple program shows how to use either method to print out the available root file systems:

import java.io.*;
import javax.swing.filechooser.*;

public class ShowRootDrives {
  public static final void printRoots(File[] roots) {
    int file;

    if(roots == null) {
      System.err.println("Could not determine root partitions.\n");

    for(file = 0; file < roots.length; ++file)

  public static final void main(String[] args) {
    FileSystemView view;

    // One way is to call File.listRoots() (only in JDK 1.2)

    // Another way is to use javax.swing.filechooser.FileSystemView
    // (only in Swing 1.1 or JDK 1.2)
    view  = FileSystemView.getFileSystemView();
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date