1

我有这个代码的类

public boolean busybox() throws IOException
{

        try
        {

        Process p =Runtime.getRuntime().exec("busybox");
        InputStream a = p.getInputStream();
        InputStreamReader read = new InputStreamReader(a);
        BufferedReader in = new BufferedReader(read);
        StringBuilder buffer = new StringBuilder();

        String line = null;

        try {

            while ((line = in.readLine()) != null) {
                buffer.append(line);
            }

        } finally {
            read.close();
            in.close();
        }

        String result = buffer.toString().substring(0, 15);
        System.out.println(result);

        return true;
        } catch (Exception e) {
        e.printStackTrace();
    }

        return false;
        }

在另一堂课我有这个代码

try {
    if(root.busybox()) {

        Busybox.setText(Html.fromHtml((getString(R.string.busybox))));


    }
    else {

        Busybox.setText(Html.fromHtml((getString(R.string.no))));

    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
            }
        });

如果我想在这个 TextView 中写入 System.out.println(result); 生成的输出;

我能怎么做?提前致谢!我做了几次尝试,但我有几个错误并且代码是错误的。

4

1 回答 1

1

change return type of public boolean busybox() to string like public String busybox() and return result.

then use

try {
String myResult=root.busybox();  
if(myResult!=null&&myResult.length>0) {

    Busybox.setText(Html.fromHtml((myResult)));


}
else {

    Busybox.setText(Html.fromHtml((getString(R.string.no))));

    }
} 
于 2013-09-28T06:39:55.840 回答