I often go to Google with "Java tutorial x" for some new topic. I almost always get a good hit at Sun and a bunch of university class notes.
FilenameFilter is an interface, so you'll have to write a class that implements FilenameFilter. That means you'll have to write the one method required by the interface. Are you comfortable writing a new little class from scratch and digging into the JavaDoc to learn about the method you need?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jan 19, 2004
hi stan...no i am not that comfortable using methods and looking at doc...to be honest..i am typing code from course text book most of the time..i have started looking more at doc..i get FilenameFilter interface but its method "public String list(FilenameFilter filter).
The method definition for list() that you show is probably for the class File. By that I mean list() is one of the methods of the File class. It can take an object of type FilenameFilter. If when you use the list() method of File to select some files from a directory to be returned in the String list, you can use the FilenameFilter object can select or reject files. You need to create a class that implements the FilenameFilter interface. Read the doc for the FilenameFilter interface. It requires that you code in the class implementing it to have one specific method. So in your class add that method and put the code in it to select files to be returned by the File.list() method.
Joined: Jan 29, 2003
It's hard to step back this far in a forum like this, much easier in person. But here we go ... start to make a little class like this:
"public class MyFilter" means you're writing a new class with that name. The simplest way to write a new class is to put it in a file with the same name, ie "MyFilter.java".
"implements FilenameFilter" means you're implementing an interface. You are required to write all the methods defined in the interface (or do some other more advanced stuff I'd like to ignore). The interface only has the one method "accept".
Back to the code you had before and fix it up to call this thing:
Now every time File.list() finds a file in the directory it will call your filter to ask if the file should go into the results. So far we coded the filter to always return true, so all files will go in just as if you had no filter. Let's make the filter more interesting:
Now it returns true for java files, false for all others.
Is this making sense? Are you in a class or working with someone to get started in Java? If not, maybe some of the gang can recommend good First Books.
Joined: Jan 19, 2004
thank you 4 your replies...i am doing home study...i have course material and java head first java....