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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 39537
    
  27
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 - updated with new look and Ping home screen widget
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
 
Similar Threads
Serializing an Object in Java ? How do i reuse it the object and where can i !
how to solve this type of stackoverflowerror...
Problem in File Browser
Couldn't check status of file/directory with casting error
The method list(FilenameFilter) in the type File is not applicable for the arguments (FilenameFilter