• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scanner Problems

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am loading a file into a scanner. The file is a text file with a listing of 88,799 names. I am reading the names and writing them out to another text file. The new text file is a list of the names along with random passwords assigned to each name.

Problem is, it stops at line 88,266. The program continues as normal, but it never completed the file. I am using a while(in.hasNext()) loop for processing the file, so the scanner should keep going until there is no more text to process. When it gets to line 88,266 it writes the name to the new file and stops, no password for that name and no more names and passwords at all.

Can anyone think of a reason for a scanner to not continue until there is no more text?
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what the cause is. I do know that Scanner objects *hide* Exceptions. Maybe you could check to see if an IOException has been thrown by calling Scanner.ioException(). If no exception has been thrown, a call to this method should return null, however if there was an exception thrown, a call to this method should help you get to the root cause. If you find that no IOException was thrown, it may be helpful if you posted the code for the method that is causing you problems.
 
Greg Roberts
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turns out I had forgotten to call close() on the Scanner and PrintWriters. There was still data in some buffer that had not been written to file at the end of the method, which is why it wasen't finishing the file. When I called close(), it flushed the buffer and finished writing to file.

Its always something small that I forget that causes the biggest problems.
 
You have to be odd to be #1 - Seuss. An odd little ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic