Created
February 5, 2018 14:58
-
-
Save ksnortum/22eeae450122a1112d3e6c1a674359e2 to your computer and use it in GitHub Desktop.
Don't close Scanner when opened to System.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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