Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why that happen

 
Indravadan T Patel
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic