• Post Reply Bookmark Topic Watch Topic
  • New Topic

whats wrong with this??

 
Sabrina Kaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have written a program that should display all the .class files in the directory and the subdirectories of the directory given at the command line as an input.

The program is compiling fine but it does not give any output. I am not able to figure out why... Pls help!!!



Thanks...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the main loop does nothing unless the file is a directory, right? The only print statement is the one that prints the absolute path of a directory. And then because you've used the filename filter, you know that the only files in "filenames" must have names that end with ".class". So unless you've got a directory named <something>.class, this program isn't going to print anything.
 
Sabrina Kaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest,

I replaced the isDirectory() with the isFile(), but the program still does not give the expected output.

I also tried to return true from the accept() method as:


When I did this, it prints all the files in the directory given on the command line.
So, does this mean that the line:

return filename.endsWith(ext); is not returning the true value for any filename???

I made sure that I tried with the directory which at least had a .class file.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, another problem I see is that the constructor has a parameter named "ext" and there's also a member named "ext"; the assignment you make in the constructor goes to the parameter, not to the member, so the member "ext" is always null. Changing the name of the constructor parameter, or using "this.ext = ...", would fix that, and then you'll be on your way. Then you'll start to get some NullPointerExceptions, as calling File.list() when the File isn't a directory returns null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!