Results 1 to 4 of 4
Thread: alternatives to Scanner?
- 05-15-2011, 09:42 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 9
- Rep Power
- 0
alternatives to Scanner?
I have written a program that runs fine. It has several subroutines, each of which runs fine (each uses scanner). The problem comes when I try to call one subroutine after another; it fails because of a scanner mismatch error. I can't figure out how to flush the scanner. If I add scan.next() to flush the buffer the program hangs waiting input. So I would like to know what my options are.
1. Write my own scanner class using buffered input stream?
2. Are there any other scanner type classes I can use?
3. I tried using scan.close(); per API, but that also terminated my program prematurely. I even tried declaring scan as new Scanner in each subroutine, and then scan.close() at end of the routine, but it also closed my entire program.
I'm resigned to writing my own input class, hoped there was an alternative out there.
-
I would fix the bugs in the program. To do that you'll need to find them first.
- 05-15-2011, 10:09 PM #3
By 'flush the Scanner', do you mean you want to throw away whatever the user has entered that your program hasn't read yet?
Perhaps a combo of hasNext to test if there is anything in the buffer and next to pull in out.
Can you post some code that shows the mismatch error? Would a has..... method to test what is in the buffer keep that from happening?
- 05-15-2011, 11:22 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Using scanner for CSV
By getName() in forum Advanced JavaReplies: 7Last Post: 06-20-2010, 04:33 PM -
Need help with scanner.
By mainy in forum New To JavaReplies: 3Last Post: 07-28-2009, 02:11 PM -
Scanner
By choko in forum New To JavaReplies: 10Last Post: 01-24-2009, 03:37 PM -
need help with scanner
By whiterex in forum New To JavaReplies: 1Last Post: 04-22-2008, 01:41 PM -
help with IP scanner
By tommy in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks