【问题标题】:BufferedReader's readLine() does not work through konsole (Kubuntu 12.10)BufferedReader 的 readLine() 不能通过 konsole (Kubuntu 12.10) 工作
【发布时间】:2013-01-06 16:56:18
【问题描述】:
public static void main(String[] args) throws IOException{

  String msg;
  BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("please type something now:");
  msg = userIn.readLine();
  System.out.println(msg);  

  userIn.close();
}

在 Eclipse 中完美运行,但是当我通过 konsole 运行时,没有打印出来。

提前致谢

【问题讨论】:

  • 尝试无缓冲的System.err,而不是缓冲的System.out

标签: java


【解决方案1】:

它依赖于操作系统。在您的情况下,System.out.println 正在使用缓冲输出。您的程序在System.out.println 将消息刷新到标准输出之前结束,因此您什么都看不到。

尝试调用System.out.flush() 强制。

相关问题:

【讨论】:

  • 不幸的是,这并没有帮助,我应该提到程序不会终止(再次仅在 konsole 中,在 eclipse 中很好)
猜你喜欢
  • 1970-01-01
  • 2016-01-17
  • 2013-12-16
  • 1970-01-01
  • 2013-03-09
  • 2016-01-08
  • 2015-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多