Java I/O How to - Get a File array containing the children files and directories








Question

We would like to know how to get a File array containing the children files and directories.

Answer

import java.io.File;
public class MainClass {
  public static void main(String[] a) {
    File myFile = new File("C:" + File.separator);
    for(File s: myFile.listFiles()){
      System.out.println(s);
    }
  }
}

The code above generates the following result.