我想通过(控制台)中的标准将输入发送到我的程序,但是当我这样做时,它会发送两个更多字符:回车和换行符。我不希望我的程序正在阅读这些内容。有没有一种方法可以发送我输入的内容而不发送这些字符?Eclipse stdin不发送回车和换行
这里是我的代码:
import java.io.IOException;
public class Main {
public static void main(String[] args) {
while (true) {
try {
System.out.println(System.in.read());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
控制台输出:
a <- Here I typed 'a' and hit enter
97 <- These three came from stdout
13 <-
10 <-
你按按一个后进入?如果您正在处理输入流中的输入内容,那么只需在您输入自定义终止符时停止输入,如果将它们转换为字符串“a”,则修剪掉回车符/新行。 – Dave 2014-09-12 16:44:24