The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reading a file from a directory. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Reading a file from a directory." Watch "Reading a file from a directory." New topic
Author

Reading a file from a directory.

Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 431


Hi all,i am trying to read from directory containing other files too.
It has listed the directory and files inside the parent directory. But i am not able to read the file which i want.
Please any suggestions!


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

Well, first of all you shouldn't use == to compare the contents of two strings for equality. That just tests to see if the two strings are the same object. You should use the equals method:

And secondly your code (at line 16) appears to assume that your current working directory has a file named "myfile.txt" in it. I'm not sure why you have all of that code looking through files in directories and then you just ignore everything that code did.
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 431


Thanks paul. Yeah,putting line 16 doesn't make any sense.
Actually i have twisted this code many times just for the sake of trying,so forgot to remove it.
Now this is happening and seems perfect,reading every single line of a file.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Reading a file from a directory.
 
Similar Threads
JAVA I/O
Flagging duplicate lines when comparing the input from two seperate text files
Reading a text file
BufferedReader Problem
client hangs after getting data from server