How can I loop a number of files in a specified folder with JAVA

I want to loop all the files in a folder with JAVA. How can I do this?
1 answers

The Java File-object can be used to represent files and folders. Create a File object to represent your folder:

File folder = new File(pathname).

Then use the method listFiles() on this object to retrieve all files and subfolders of this folder.

for(File file : folder.listFiles()) {
    // doSomething(file)

See the Java documentation for File.listFiles()