小编use*_*401的帖子

readline()在Java中返回null

我正在尝试在我的Java程序中读取stdin.我期待一系列数字后跟换行符,例如:

6  
9  
1  
Run Code Online (Sandbox Code Playgroud)

通过eclipse内置控制台提供输入时,一切顺利.但是当使用Windows命令行时,程序会打印:

Received '6'.  
Received 'null'.  
Invalid input. Terminating. (This line is written by another function that does an Integer.parseint()).  
Run Code Online (Sandbox Code Playgroud)

我的代码是:

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";  
}  
Run Code Online (Sandbox Code Playgroud)

有线索吗?

java stdin readline

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

readline ×1

stdin ×1