Android调用Linux命令修改文件权限的两种实现方式

来源:互联网 发布:java 调用rest接口 编辑:程序博客网 时间:2024/06/05 02:11
public class FileMode {    public static void changeFileModeByCmd(String file) {        String[] command = {"chmod", "777", file};        ProcessBuilder builder = new ProcessBuilder(command);        try {            builder.start();        } catch (IOException e) {            e.printStackTrace();        }    }    public static void changeFileModeBySys(String filename) {        try {            Process p = Runtime.getRuntime().exec("chmod 644 " + filename);            int status = p.waitFor();            if (status == 0) {                //chmod succeed            } else {                //chmod failed            }        } catch (IOException | InterruptedException e) {            e.printStackTrace();        }    }}
原创粉丝点击