在android代码中 使用Linux命令做一些文件操作,如:移动,复制,删除等。
- 删除文件
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;
}