Scanner is never closed

I am assuming you are using java 7, thus you get a compiler warning, when you don’t close the resource you should close your scanner usually in a finally block.

Scanner scanner = null;
try {
    scanner = new Scanner(;
    //rest of the code
finally {

Or even better: use the new Try with resource statement:

try(Scanner scanner = new Scanner({
    //rest of your code

Leave a Comment