【发布时间】:2011-08-26 21:01:05
【问题描述】:
我想运行可执行文件,例如 ping(或任何其他提供连续输出的)并读取其输出并在我的 GUI 中打印。
我使用以下方法来运行我的命令:
command=Runtime.getRuntime().exec("ping www.google.com");
我正在读取如下输出:
BufferedReader in = new BufferedReader(new InputStreamReader(command.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line+"\n");
}
这很好用,尽管与我使用 adb -d shell 执行 ./excutable 所花费的时间相比,显示输出很晚。
因为我想在 gui 中输出此输出(行),所以我制作了一个 TextView 并将输出(行)附加为:
txtview=(TextView)findViewById(R.id.textview);
while ((line = in.readLine()) != null) {
txtview.append(line+"\n");
System.out.println(line+"\n");
}
但这会使我的应用程序崩溃。 请告诉我如何解决这个问题。
【问题讨论】:
标签: android user-interface android-ndk native bufferedreader