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.
More Related Contents:
- Conditional Statement on Java7
- How to use java.util.Scanner to correctly read user input from System.in and act on it?
- java.util.NoSuchElementException – Scanner reading user input
- How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner
- How can I read input from the console using the Scanner class in Java?
- Scanner vs. BufferedReader
- How do I use a delimiter with Scanner.useDelimiter in Java?
- Why am I getting InputMismatchException?
- Scanner error with nextInt() [duplicate]
- NoSuchElementException with Java.Util.Scanner
- Read CSV with Scanner()
- Scanner doesn’t see after space
- How do I keep a Scanner from throwing exceptions when the wrong type is entered?
- Java String Scanner input does not wait for info, moves directly to next statement. How to wait for info? [duplicate]
- Close Scanner without closing System.in
- How to use multiple Scanner objects on System.in?
- Read .txt file into 2D Array
- How to interrupt java.util.Scanner nextLine call
- Java scanner not going through entire file
- java.util.scanner throws NoSuchElementException when application is started with gradle run
- What does scanner.close() do?
- Scanner skipping every second line from file [duplicate]
- How to read a text file directly from Internet using Java?
- Java Scanner doesn’t wait for user input [duplicate]
- Why is hasNext() False, but hasNextLine() is True?
- How to use multiple Scanner objects on System.in in Java?
- Scanner is never closed
- Exception in thread “main” java.io.FileNotFoundException: Error
- Why can’t I enter a string in Scanner(System.in), when calling nextLine()-method?
- Java Scanner class reading strings