by Dinesh Thakur Category: Stream

File is a predefined class present in package. listFiles method is a predefined method of File class.

This method is used to show the list of files present in the specified directory.
Syntax- public File[] listFiles()

Here is the Java Example for List All Files in a Given Directory  :


public class ListAllFiles
              public static void main(String args[])
             File f = new File("c:\\");
             File[] f1 = f.listFiles();
             for (int AllFiles=0; AllFiles<f1.length; AllFiles++)

List All Files in a Given Directory

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles