dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 20, 2020

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
 
Thanks for your registration, follow us on our social networks to keep up-to-date