3:53 pm - Saturday March 25, 8834

File Program to print abstract pathname does not denote a directory

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

// Program to print abstract pathname does not denote a directory//

//Author:CandidJava//

//Description: Program returns an array of abstract pathnames denoting the files not including the directory//

import java.io.*;

import java.util.*;

public class FileFilterTest

{

public static void main(String[] args)

{

FileFilterTest ft=new FileFilterTest();

}

public FileFilterTest()

{

File dir = new File("e:/aa");

// list the files using FileFilter

File[] files = dir.listFiles(new filefilter1());

for (File f : files)

{

System.out.println("file: " + f.getName());

}

}

}

//sub class to implementĀ  file filter interface

import java.io.*;

class filefilter1 implements FileFilter

{

private final String[] Extensions =new String[] {"class"};

//override accept method of the interface

public boolean accept(File file)

{

for (String extension : Extensions)

{

//condition to be checked

if (file.getName().toLowerCase().endsWith(extension))

{

return true;

}

}

return false;

}

}

 

OUTPUT:

D:candidjava /io/file> javacĀ  FileFilterTest.java

D:candidjava /io/file> java FileFilterTest

File: DirFilter.class

File: filefilt.class

File: filename.class

File: FileFilter.class

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply