Java IO Tutorial - Java File.listRoots()








Syntax

File.listRoots() has the following syntax.

public static File [] listRoots()

Example

In the following code shows how to use File.listRoots() method.

/*  www .ja va  2s  . c o  m*/

import java.io.File;

public class Main {
  public static void main(String[] args) {

    // returns pathnames for files and directory
    File[] paths = File.listRoots();

    // for each pathname in pathname array
    for (File path : paths) {
      // prints file and directory paths
      System.out.println(path);
    }

  }
}

The code above generates the following result.