Back
I need to create a list with all names of the files in a folder.
For example, if I have:
000.jpg012.jpg013.jpg
000.jpg
012.jpg
013.jpg
I want to store them in a ArrayList with [000,012,013] as values.
What's the best way to do it in Java ?
PS: I'm on Mac OS X
You can try:
File folder = new File("your/path");File[] listOfFiles = folder.listFiles();for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); }}
File folder = new File("your/path");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
31k questions
32.8k answers
501 comments
693 users