Java Get All Files In Directory

[Solved] Java Get All Files In Directory | Java - Code Explorer | yomemimo.com
Question : how to get all the names of the files in a folder in java?

Answered by : busy-bug-pgzs7emzx5o9

List<String> results = new ArrayList<String>();
File[] files = new File("/path/to/the/directory").listFiles();
//If this pathname does not denote a directory, then listFiles() returns null.
for (File file : files) { if (file.isFile()) { results.add(file.getName()); }
}

Source : https://stackoverflow.com/questions/5694385/getting-the-filenames-of-all-files-in-a-folder | Last Update : Fri, 19 Jun 20

Question : java read all files in a directory

Answered by : thankful-tarantula-vkd4rkgn4czm

public void listFilesForFolder(final File folder) { for (final File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory()) { listFilesForFolder(fileEntry); } else { System.out.println(fileEntry.getName()); } }
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);

Source : https://stackoverflow.com/questions/1844688/how-to-read-all-files-in-a-folder-from-java | Last Update : Wed, 16 Sep 20

Answers related to java get all files in directory

Code Explorer Popular Question For Java