Simply use a custom FilterInputStream instead of System.in:
new FilterInputStream(System.in) {
@Override
public void close() throws IOException {
//don't close System.in!
}
}
More Related Contents:
- How to use java.util.Scanner to correctly read user input from System.in and act on it?
- Conditional Statement on Java7
- 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?
- Close a Scanner linked to System.in
- Scanner vs. BufferedReader
- How do I use a delimiter with Scanner.useDelimiter in Java?
- Why am I getting InputMismatchException?
- Scanner error with nextInt() [duplicate]
- Read CSV with Scanner()
- Scanner NoSuchElementException
- Scanner doesn’t see after space
- Reading a .txt file using Scanner class in Java
- Reading in from System.in – Java [duplicate]
- Java Multiple Scanners
- 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]
- Eclipse reading stdin (System.in) from a file
- Closing BufferedReader and System.in
- 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?
- Weird behaviour with Scanner#nextFloat