Close a Scanner linked to System.in

The simplest thing is to not close Scanner if you don’t want to close the underlying stream.

Ideally you should create just one Scanner which you use for the life of the program. In any case, it appears you don’t have a good reason to close it.

Leave a Comment