How to list all files in a directory using Java?

You can get the list of files in a directory −

  • Create a directory object using the File class.
  • Get the list of directories in it using the getName() method.



public class FindingDirectories {
   public static void main(String args[]) {
      String dir ="C:/Users/Tutorialspoint/Desktop/movies";
      File directory = new File(dir);
      File[] fileList = directory.listFiles();

      for(File file: fileList) {


Arundhati HD.mp4
Okka Ammai Tappa.mkv
Padamati Sandhya Ragam.mp4
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know