android执行外部程序,类似DELPHI里的EXEC函数
16lz
2021-01-23
多的不说,直接上代码:
public String exec(String command) {
StringBuffer output = new StringBuffer();Log.d("exec", command);
try {
Process process = Runtime.getRuntime().exec(command);
DataInputStream stdout = new DataInputStream(process.getInputStream());
String line;
while ((line = stdout.readLine()) != null) {
output.append(line).append('\n');
}
process.waitFor();
} catch (Exception e) {
output.append('\n').append(e.toString());
}
return output.toString();
}
经过验证,此方法在1.6、2.0下都是有效的。
更多相关文章
- android典型代码系列(一)------android调试
- Android 动画框架代码分析
- Android 7.0 app代码修改抓包
- Android WebView中的JavaScript调用android方法
- [导入]Android平台上四种保存数据的方法
- android延续按两次返回退出程序(完整代码)
- Android的关键的持久数据应该在onPause()方法中保存
- Android 实现在Java代码中修改UI界面,并修改界面
- Android添加单元测试的方法与步骤