Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Apr 20, 2020

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Get 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());
  }
}
Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
codeschool.com
w3schools.com