首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改系统文件权限

更改系统文件权限
EN

Stack Overflow用户
提问于 2012-08-06 04:15:55
回答 1查看 5.2K关注 0票数 3

我真的什么都试过了:

现在,假设我已经重新挂载为root用户,因此文件系统上的RW权限(AndroidVersion2.3.7):

代码语言:javascript
复制
Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("chmod -c 0777 /system/etc/customization/settings/com/android/browser/custom_settings.xml\n");
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();

或者:

代码语言:javascript
复制
Process process = Runtime.getRuntime().exec("su -c \"/system/etc/customization/settings/com/android/browser/custom_settings.xml\"");

或者:

代码语言:javascript
复制
Class<?> fileUtils = Class.forName("android.os.FileUtils");
            Method setPermissions =
                fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class);
            int a = (Integer) setPermissions.invoke(null, "/system/etc/customization/settings/com/android/browser/custom_settings.xml", 0777, -1, -1);

行为是一样的:什么都不会发生。然而,如果我来自亚行外壳的chmod工作得很好。如何在代码中更改该文件的权限?

EN

回答 1

Stack Overflow用户

发布于 2012-10-22 08:33:28

这是我的解决方案:

代码语言:javascript
复制
        Process sh = Runtime.getRuntime().exec("su", null, new File("/system/bin/"));
        OutputStream os = sh.getOutputStream();

        os.write(("chmod 777 <filepath>").getBytes("ASCII"));
        os.flush();
        os.close();
        sh.waitFor();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11822500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档