我正在嘗試讀取我的Java程序中的stdin。我期待一連串的數字,然後換行,如:readline()在Java中返回null
6
9
1
當提供通過Eclipse內置控制檯,一切順利的輸入。但是,使用Windows命令行程序打印時:
Received '6'.
Received 'null'.
Invalid input. Terminating. (This line is written by another function that does an Integer.parseint()).
我的代碼是:
static String readLineFromStdIn(){
try{
java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
String input = new String();
input = stdin.readLine();
System.out.println("Received '" + input + "'");
return(input);
}catch (java.io.IOException e) {
System.out.println(e);
}
return "This should not have happened";
}
任何線索?
我在Eclipse控制檯中輸入所有數字後輸入。在Windows中,我做「java -jar program.jar
user1259401
2012-03-09 13:53:22