dcsimg
 

Submitted by: Octavia Anghel(octaviaanghel@gmail.com)

Monday Apr 20th 2020 by Octavia Anghel

Language: Java, Expertise: Intermediate: See how to get all the file names in a directory.

See how to get all the file names in a directory, as shown below:

File folder = new File("your/path");
File[] listOfFiles = folder.listFiles();

for (int i = 0; i    if (listOfFiles[i].isFile()) {
    System.out.println("File " + listOfFiles[i].getName());
  } else if (listOfFiles[i].isDirectory()) {
    System.out.println("Directory " + listOfFiles[i].getName());
  }
}
Home
Mobile Site | Full Site