wood burning stoves
The moose likes I/O and Streams and the fly likes why that happen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "why that happen" Watch "why that happen" New topic

why that happen

Indravadan T Patel

Joined: Sep 09, 2007
Posts: 29
Hi All,

1.import java.io.*;
3.class OnlyExt implements FilenameFilter{
4. String ext;
6. public OnlyExt(String ext){
7. this.ext="." + ext;
8. }
10. public boolean accept(File dir,String name){
11. return name.endsWith(ext);
12. }
15.public class FilterFiles{
16. public static void main(String args[]) throws IOException{
17. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
18. System.out.println("Please enter the directory name : ");
19. String dir = in.readLine();
20. System.out.println("Please enter file type : ");
21. String extn = in.readLine();
22. File f = new File(dir);
23. FilenameFilter ff = new OnlyExt(extn);
24. String s[] = f.list(ff);
26. for (int i = 0; i < s.length; i++)
27. {
28. System.out.println(s[i]);
29. }
30. }

i can't understand what happen at line no :22 23 24. please any help me to find out why that type of flow of pross occur.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Well, what does happen if you run code? Once you know that, you may be in a position to make an attempt at explaining why it happens.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Your variable f is a File, and you call list(ff). Look up the doc for File list(FilenameFilter). Make the accept() method on your filter print out its arguments. See if that makes it clear how list and filter interact. And let us know if not.

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
I agree. Here's the link: http://aspose.com/file-tools
subject: why that happen
It's not a secret anymore!