写入sys文件 - (eacces)权限被拒绝

时间:2017-01-11 23:55:42

标签: android root su

我正在尝试在Android上编辑一个sys文件,但我一直在EACCES(Permission denied)

我可以更改文件的权限,从-r-r-r更改为-rwx-rwx-rwx,但我仍然无法对其进行编辑。

public void changePermissions(String permissions, String path) {
    DataOutputStream os = null;
    Process p = null;
    try {
        p = Runtime.getRuntime().exec("su");
        os = new DataOutputStream(p.getOutputStream());
        os.writeBytes("chmod " + permissions + " " + path + "\n");
        os.writeBytes("exit\n");

        os.flush();
        p.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (os != null) {
            try {
                os.close();
                p.destroy();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
File file = new File("/sys/class/graphics/fb0/lcd_backlight");

BufferedReader in = new BufferedReader(new FileReader(file)); // I'm able to read it
PrintWriter out = new PrintWriter(new FileWriter(file)); // This line throws the error

0 个答案:

没有答案