8:31 pm - Thursday April 27, 2017

To find list of files using listFiles()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

This tutorial explains how  To find list of files using listFiles() method,we have created an object of File class and parse the directory through the constructor of the File class.


import java.io.File;

public class ListFile

{

public static void main(String[] args)

{

String path = “/home/mathan/Documents”;

File folder = new File(path);

File[] list = folder.listFiles();

for (int i = 0; i < list.length; i++) System.out.println(list[i]); } } [/java] Output

/home/mathan/Documents/abcd.txt

/home/mathan/Documents/apache-tomcat-7.0.39

/home/mathan/Documents/eclipse

/home/mathan/Documents/test

/home/mathan/Documents/apache-ant-1.8.4

/home/mathan/Documents/kanthi

/home/mathan/Documents/ws

/home/mathan/Documents/cwork

/home/mathan/Documents/basic

/home/mathan/Documents/mongodb

/home/mathan/Documents/tomcat7

BACK

Filed in: Java Examples

Comments are closed.