使用命令进行文件操作

来源:互联网 发布:java json格式化输出 编辑:程序博客网 时间:2024/05/17 23:39

在android代码中 使用Linux命令做一些文件操作,如:移动,复制,删除等。

  1. 删除文件
     public boolean deleteTmpFile(String tmpFile){       try {            String command="rm  "+tmpFile;            Runtime runtime=Runtime.getRuntime();        Process proc=runtime.exec(command);       } catch (IOException e) {        e.printStackTrace();        return false;       }         return true;       }

2.移动文件

        /**         移动文件         @param tmpFile  缓存文件位置,被移动         @param localFile目标文件位置         @return        */   public boolean moveFile(String tmpFile,String localFile){       try {       String command="mv  "+tmpFile+"  "+localFile;        Runtime runtime=Runtime.getRuntime();       Process proc=runtime.exec(command);       } catch (IOException e) {       e.printStackTrace();       return false;       }       return true;     }

3 复制文件

   public boolean cpFile(String tmpFile){       try {       String command="cp  "+tmpFile;       Runtime runtime=Runtime.getRuntime();        Process proc=runtime.exec(command);       } catch (IOException e) {        e.printStackTrace();        return false;       } return true;    }
0 0
原创粉丝点击