Android使用Linux命令执行文件操作
16lz
2022-03-30
import java.io.IOException;
import java.util.ArrayList;
/** * File operators. Like: delete, create, move... * Use linux shell to implement these operators. * So, only for linux like operator system. * All return the execute process, and if the requested program can not be executed, * may throws IOException. * And all files or diretorys String parameters are absolute path. * The return new {@code Process} object that represents the native process. * */ public class LinuxFileCommand { public final Runtime shell; //private static final int c = 0; /** * Constructor. /data/busybox/ * @param * interface with the environment in which they are running * */ public LinuxFileCommand(Runtime runtime) { // TODO Auto-generated constructor stub shell = runtime; } /** Delete {@code file} file, nerver prompt*/ public final Process deleteFile(String file) throws IOException{ String[] cmds = {"rm", file}; return shell.exec(cmds); } public final Process delete(String file) throws IOException { String[] cmds = {"rm", "-r", file}; return shell.exec(cmds); } public final Process deleteMult(String[] cmds) throws IOException{ return shell.exec(cmds); } /** Delete {@code dire} directory, nerver prompt*/ public final Process deleteDirectory(String dire) throws IOException{ String[] cmds = {"rm", "-r", dire}; return shell.exec(cmds); } /** Create {@code file} file, if file has already exist, update the * file access and modification time to current time. * @throws IOException * */ public final Process createFile(String file) throws IOException { String[] cmds = {"touch", file}; return shell.exec(cmds); } /** Create directory. If parent path is not existed, also create parent directory * @throws IOException */ public final Process createDirectory(String dire) throws IOException{ String[] cmds = {"mkdir", dire}; return shell.exec(cmds); } /** Move or rename(if they in the same directory) file or directory * @throws IOException */ public final Process moveFile(String src, String dir) throws IOException{ String[] cmds = {"mv", src, dir}; return shell.exec(cmds); } /** Copy file * @throws IOException */ public final Process copyFile(String src, String dir) throws IOException{ String[] cmds = {"cp", "-r", src, dir}; return shell.exec(cmds); } /**` * File soft Link * @throws IOException * */ public final Process linkFile(String src, String dir) throws IOException{ String[] cmds = {"ln", "-l", src, dir}; return shell.exec(cmds); } public final Process du_s(String file) throws IOException{ String[] cmds = {"du", "-s", file}; return shell.exec(cmds); }
public final Process ls_lhd(String file) throws IOException{ String[] cmds = {"ls", "-l", file}; return shell.exec(cmds); } public final Process ls_Directory(String directory) throws IOException{ if (directory.equals("/")) directory = ""; String[] cmds = {"ls", "-a", directory}; return shell.exec(cmds); } }
import java.util.ArrayList;
/** * File operators. Like: delete, create, move... * Use linux shell to implement these operators. * So, only for linux like operator system. * All return the execute process, and if the requested program can not be executed, * may throws IOException. * And all files or diretorys String parameters are absolute path. * The return new {@code Process} object that represents the native process. * */ public class LinuxFileCommand { public final Runtime shell; //private static final int c = 0; /** * Constructor. /data/busybox/ * @param * interface with the environment in which they are running * */ public LinuxFileCommand(Runtime runtime) { // TODO Auto-generated constructor stub shell = runtime; } /** Delete {@code file} file, nerver prompt*/ public final Process deleteFile(String file) throws IOException{ String[] cmds = {"rm", file}; return shell.exec(cmds); } public final Process delete(String file) throws IOException { String[] cmds = {"rm", "-r", file}; return shell.exec(cmds); } public final Process deleteMult(String[] cmds) throws IOException{ return shell.exec(cmds); } /** Delete {@code dire} directory, nerver prompt*/ public final Process deleteDirectory(String dire) throws IOException{ String[] cmds = {"rm", "-r", dire}; return shell.exec(cmds); } /** Create {@code file} file, if file has already exist, update the * file access and modification time to current time. * @throws IOException * */ public final Process createFile(String file) throws IOException { String[] cmds = {"touch", file}; return shell.exec(cmds); } /** Create directory. If parent path is not existed, also create parent directory * @throws IOException */ public final Process createDirectory(String dire) throws IOException{ String[] cmds = {"mkdir", dire}; return shell.exec(cmds); } /** Move or rename(if they in the same directory) file or directory * @throws IOException */ public final Process moveFile(String src, String dir) throws IOException{ String[] cmds = {"mv", src, dir}; return shell.exec(cmds); } /** Copy file * @throws IOException */ public final Process copyFile(String src, String dir) throws IOException{ String[] cmds = {"cp", "-r", src, dir}; return shell.exec(cmds); } /**` * File soft Link * @throws IOException * */ public final Process linkFile(String src, String dir) throws IOException{ String[] cmds = {"ln", "-l", src, dir}; return shell.exec(cmds); } public final Process du_s(String file) throws IOException{ String[] cmds = {"du", "-s", file}; return shell.exec(cmds); }
public final Process ls_lhd(String file) throws IOException{ String[] cmds = {"ls", "-l", file}; return shell.exec(cmds); } public final Process ls_Directory(String directory) throws IOException{ if (directory.equals("/")) directory = ""; String[] cmds = {"ls", "-a", directory}; return shell.exec(cmds); } }
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer