how can i modify this program to list the *.java file using FIlenameFilter

M

mahesh

public class MatcherEx //implements FilenameFilter
{
static String suffix=".txt";
private FilenameFilter filter;

public static void main(String[] args)throws IOException {

File fs=new File("\\d:");
File []path1=fs.listFiles();

for(int i=0;i<path1.length;i++)
{
System.out.println("\n"+path1.toString());
}
}
}
 
A

Andrew Thompson

mahesh wrote:

Sub: how can i modify this program to list the *.java file using
FIlenameFilter

Try using Java code.

Andrew T.
 
K

Knute Johnson

mahesh said:
public class MatcherEx //implements FilenameFilter
{
static String suffix=".txt";
private FilenameFilter filter;

public static void main(String[] args)throws IOException {

File fs=new File("\\d:");
File []path1=fs.listFiles();

for(int i=0;i<path1.length;i++)
{
System.out.println("\n"+path1.toString());
}
}
}


Here you go -

import java.io.*;

public class test implements FilenameFilter {
public test() {
File fs = new File("c:");
String[] paths = fs.list(this);
for (int i=0; i<paths.length; i++)
System.out.println(paths);
}

public boolean accept(File dir, String name) {
if (name.endsWith(".java"))
return true;
else
return false;
}

public static void main(String[] args) {
new test();
}
}
 
G

GenxLogic

If you are using FileNameFilter then you have to make your own
FileNameFilter which will implement FileNameFilter Interface and will
implement the public boolean accept(File file,String name) function.
this function will conatin the logic you want to apply for the
selection of the files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top