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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 3599
    
  14

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:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reading a text file using FileReader & BufferedReader : Unexpected output !
 
Similar Threads
Issue with reading from a file
FILE I/O
To find a largest sector in a given input string of 1's and 0's
Working with file and directories..
to read a file and store it