List contents of a directory - Java File Path IO

Java examples for File Path IO:Directory Content

Description

List contents of a directory

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
    File file = new File("C://FileIO");
     String[] files = file.list();
   // w  ww .j a v  a2 s .c  o  m
     System.out.println("Listing contents of " + file.getPath());
     for(int i=0 ; i < files.length ; i++)
     {
       System.out.println(files[i]);
     }
  }
}

Related Tutorials