I have a Scanner
linked to System.in
. Now, after using the Scanner
, I should close it, as it is bad coding practice to leave it open.
One option is to wrap your System.in
stream in a CloseShieldInputStream
that prevents it from being closed. Your reader would then use the CloseShieldInputStream
rather than the raw System.in
stream.
Here is the API for the class: http://commons.apache.org/io/apidocs/org/apache/commons/io/input/CloseShieldInputStream.html