简体   繁体   English

为什么以下代码打印值无法运行?

[英]Why isn't the following code printing values run time?

as the cat /proc/meminfo provides dynamic details I want to update the text area system values change. 由于cat / proc / meminfo提供了动态详细信息,因此我想更新文本区域的系统值更改。 I tried the following.But doesn't work.Please help 我尝试了以下方法,但不起作用。请帮助

Thread th=new Thread(new Runnable() {
public void run() {
while(true)
{
  try{
       p = Runtime.getRuntime().exec("cat /proc/meminfo");
         BufferedReader br = new BufferedReader(
                     new InputStreamReader(p.getInputStream()));
                 while ((s = br.readLine()) != null)
                 {
                     textArea.append(s+"\n");
                 }
                 p.waitFor();
                 p.destroy();
      }
      catch(Exception e)
      {

      }
 }
});     

As far as I can see, textArea isn't doing anything. 据我textAreatextArea没有做任何事情。 To print values in Java, use System.out.println . 要使用Java打印值,请使用System.out.println

You can replace: 您可以替换:

textArea.append(s+"\n");

With: 带有:

System.out.print(s+"\n");

Or even easier: println automatically appends a new line after your text: 甚至更简单: println在文本之后自动添加新行:

System.out.println(s);

Another issue is that the readLine method could be hanging your program. 另一个问题是readLine方法可能会挂起您的程序。 Step through with a debugger if that's the case. 如果是这种情况,请逐步调试器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM