Sorry to bother you guys, but I cannot find answer when did a lot of searching.
Here is my code, it's pretty simple:
import java.io.IOException;
import java.io.ObjectInputStream;
public class Test {
public static void main(String[] args) {
System.out.println(args.length);
ObjectInputStream is;
try {
is = new ObjectInputStream(System.in);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String input = System.console().readLine();
System.out.println("input: " + input);
}
}
With command like : java Test, everything works find, and I can get input from console by typing something. BUT, with redirection in the command, I cannot type on console to input, the application will return immediately.
java Test /d/aa.dat < /d/example.dat
Exception in thread "main" java.lang.NullPointerException
at Test.main(Test.java:17)
I think the root cause is when I use redirection in command line with a file, the default System.in is override by file "example.dat".
My question is how can I restore the default System.in to let user input from console?
Thank you so much.