This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Reading consecutive text file lines using scanner and actionListener event  RSS feed

 
Greenhorn
Posts: 1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be grateful if someone can come up with some suggestions please, ( I am currently revising for an exam).I have been having trouble reading consecutive lines from a text file using scanner through an actionListener event (button press or a mouseListener event, mousePressed); so that each button press reads the first line of text and the next button press reads the second line and so on. I cannot use a collection to store the text first.
I have put together a small example of what i am trying. I can read the whole text file no problem and i can read the first line of text without a problem. I have considered using some form of count comparison but cannot get that to work either. There are various commented out statements included as part of my attempts. Thanks



Please ignore my request I have finally solved the problem. By declaring the scanner object as an instance variable and instantiating it in the constructor inside a try catch block and removing the matching code from the button watcher, it all works.
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!