Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading pairs of lines from a file  RSS feed

 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This what the data file looks like -



The problem was to make code which will combine consecutive lines which contain some data into one line and print it. I made a solution that works. But I am not confident if it is
the best way. Can someone please suggest improvements or errors in my approach. Thank you friends, I like you.



 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be better to check if there is a next line rather than relying on an exception that is thrown. The purpose of exception is to handle unexpected scenarios. You are expecting the file to end at some point.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!