• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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 ?
 
Saloon Keeper
Posts: 8224
144
  • 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.
 
Rancher
Posts: 618
  • X 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:
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!