tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > List Files

List Files 

The following example shows how to list the file of a given directory.

File Name  :  
com/bethecoder/tutorials/io/ListFilesTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

import java.io.File;

public class ListFilesTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    File directory = new File("C:\\NEW");
    File [] filesInDir = directory.listFiles();
    
    System.out.println("Directory file listing of " + directory);
    for (int i = ; i < filesInDir.length ; i ++) {
      System.out.println(filesInDir[i]);
    }
  }

}
   

It gives the following output,
Directory file listing of C:\NEW
C:\NEW\BIOSinfo.log
C:\NEW\file_ops.txt
C:\NEW\IPC.LOG
C:\NEW\NEW_SUB
C:\NEW\readonly_file.txt
C:\NEW\software.tsv
C:\NEW\test.txt



 
  


  
bl  br