This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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: 3392
    
    9
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 !
 
Similar Threads
Working with file and directories..
to read a file and store it
FILE I/O
To find a largest sector in a given input string of 1's and 0's
Issue with reading from a file