File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 3649
    
  17

You are reading from your file twice at each iteration, but you are only storing half of the lines in data.
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 !