• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Stephan van Hulst
Saloon Keeper
Posts: 6985
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are reading from your file twice at each iteration, but you are only storing half of the lines in data.
 
Tom Reilly
Rancher
Posts: 618
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!