Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Clearing all remaining input in System.in

835847Nov 9 2011 — edited Nov 9 2011
I am at a point in my program where I need to clear garbage out of System.in and I have tried several ways to do this.

When Scanner reads the garbage, an exception is thrown. Within this exception I attempt to clear System.in by resetting it, reading all remaining bytes, marking it, using BufferedInputStream to no avail.

One System.in.read() blocks, there is no return value for EOF (-1).

Any clear ways to reset the System.in and clear the InputStream?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2011
Added on Nov 9 2011
3 comments
192 views