When i use scanner.close()
, System.in
parameter is also closed.
I can understand a little this process with searching this site.
Some said if System.in is closed, it can't be reopened.
But they didn't have conviction for that.
So my question is this:
How to System.in
reopen? or is that impossible?
for understanding my question, i put some example code here
public void scannerTest() {
Scanner input = new Scanner(System.in);
int i = input.nextInt();
input.close();
Scanner input2 = new Scanner(System.in);
int j = input2.nextInt();
}
and result on console
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at repeat.Test.scannerTest(Test.java:55)
at repeat.Test.<init>(Test.java:19)
at repeat.Test.main(Test.java:11)