Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Don't close Scanner when opened to System.in
package net.snortum.play;
import java.util.Scanner;
public class ScannerClosePlay {
public static void main(String[] args) {
Scanner scanner1 = new Scanner(System.in);
System.out.print("Enter foo: ");
String foo = scanner1.nextLine();
scanner1.close();
Scanner scanner2 = new Scanner(System.in);
System.out.print("Enter bar: ");
String bar = scanner2.nextLine(); // Exception
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.