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?
Greg Roberts<br />CIS Student<br />University of West Florida
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.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Feb 05, 2005
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.