permaculture playing cards
The moose likes Beginning Java and the fly likes Reading a text file using FileReader & BufferedReader : Unexpected output ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading a text file using FileReader & BufferedReader : Unexpected output !" Watch "Reading a text file using FileReader & BufferedReader : Unexpected output !" New topic
Author

Reading a text file using FileReader & BufferedReader : Unexpected output !

Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

the program below compiles properly. Its supposed to "print" the below source code saved inside "mytxt.txt" . But i get only some parts of the text in output.




PS : how do i upload the screen shot of the console output from my pc ?

SCJP 6. Learning more now.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4087
    
  18

You are reading from your file twice at each iteration, but you are only storing half of the lines in data.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I surmise that it is only printing the even numbered lines in your file. That is because your while statement is reading a line and then you read another line in the while loop. And you only print the line that was read in the loop. Try:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a text file using FileReader & BufferedReader : Unexpected output !
 
It's not a secret anymore!