Turn Desktop View Off
by Dinesh Thakur

File is a predefined class present in java.io 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  :

import java.io.*;

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++)
                   {
                        System.out.println(f1[AllFiles].toString());
                   }
        }
}

List All Files in a Given Directory