aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "why that happen" Watch "why that happen" New topic
Author

why that happen

Indravadan T Patel
Greenhorn

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

1.import java.io.*;
2.
3.class OnlyExt implements FilenameFilter{
4. String ext;
5.
6. public OnlyExt(String ext){
7. this.ext="." + ext;
8. }
9.
10. public boolean accept(File dir,String name){
11. return name.endsWith(ext);
12. }
13.}
14.
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);
25.
26. for (int i = 0; i < s.length; i++)
27. {
28. System.out.println(s[i]);
29. }
30. }
31.}

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
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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.


Ping & DNS - my free Android networking tools app
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
 
wood burning stoves
 
subject: why that happen