2012-08-06 120 views
3

我真的尝试了一切:更改系统文件的权限

现在,假设我已经重新安装的根目录,因此RW文件系统权限(Android版本2.3.7) :

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(); 

或:

Process process = Runtime.getRuntime().exec("su -c \"/system/etc/customization/settings/com/android/browser/custom_settings.xml\""); 

或:

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); 

的行为是一样的:没有任何反应。而如果我从adb shell的chmod工作正常。我如何在代码中更改该文件的权限?

回答

1

这里是我的解决方案:

 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(); 
上所有的答案
+0

所以这是对我的作品的人。 – 2013-07-22 06:18:52

+0

http://examples.javacodegeeks.com/core-java/io/file/set-file-permissions-in-java-example/ – vangorra 2014-09-04 21:08:26