Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the filenames of all files in a folder [duplicate]

I need to create a list with all names of the files in a folder.

For example, if I have:

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

like image 795
user680406 Avatar asked Apr 17 '11 15:04

user680406


People also ask

Does Windows 11 have a duplicate file finder?

WinZip System Utilities Suite can easily locate duplicate files in a folder or directory and it's compatible with any Windows 11 PC operating system. You may scan your entire computer or just certain folders. If you need to scan your whole computer, simply press the Scan button to begin your duplicate file search.


1 Answers

You could do it like that:

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());   } } 

Do you want to only get JPEG files or all files?

like image 51
RoflcoptrException Avatar answered Oct 20 '22 02:10

RoflcoptrException