在Linux中调用本地命令

字体大小: 中小 标准 ->行高大小: 标准

在Linux中调用本地命令,使用Runtime.getRuntime().exec("command")的方法返回一个Process进程,如Process pros=

Runtime.getRuntime().exec("mv ./adm/wtmpx ./adm/wtmpx20081026");

等同于在Linux中把wtmpx文件备份成wtmpx20081026并删除wtmpx。

调用pros.getInputStream() pros.getOutputStream返回输入输出流

可以通过过滤流进行包装操作

如BufferedReader br=new BufferedReader(new InputStreamReader(

pros.getInputStream());

String str=null;

while((str=br.readLine())!=null){

System.out.println(str);

}

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/52091.html