Android之应用中执行Linux命令
16lz
2021-01-24
http://www.2cto.com/kf/201303/196718.html
package com.java2novice.processbuilder; import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.List; public class MyMultipleCommandsEx { public static void main(String a[]){ InputStream is = null; ByteArrayOutputStream baos = null; List commands = new ArrayList(); commands.add("ls"); commands.add("-l"); commands.add("/Users/java2novice/"); ProcessBuilder pb = new ProcessBuilder(commands); try { Process prs = pb.start(); is = prs.getInputStream(); byte[] b = new byte[1024]; int size = 0; baos = new ByteArrayOutputStream(); while((size = is.read(b)) != -1){ baos.write(b, 0, size); } System.out.println(new String(baos.toByteArray())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { if(is != null) is.close(); if(baos != null) baos.close(); } catch (Exception ex){} } }}
http://blog.csdn.net/qiujuer/article/details/38086071
更多相关文章
- C语言函数的递归(上)
- No compatible targets were found....
- Android(安卓)Widget开发
- 初学Android,数据存储之SD卡文件浏览器(四十四)
- android读取raw下面的文件
- android 屏幕测试程序 测试R G B三色 和 全黑, 全白5种状态
- Linux 统计代码行数
- 【android 文件的基本操作】
- TextView 在xml文件中的解释 android