我正在开发一个可以将应用程序的数据恢复到/ data / data / {packageName}的应用程序.恢复文件后,我将权限设置为rw- r– r–.我这样设置:
public int chmod(File path,int mode) throws Exception { Class fileUtils = Class.forName("android.os.FileUtils"); Method setPermissions = fileUtils.getMethod("setPermissions",String.class,int.class,int.class); return (Integer) setPermissions.invoke(null,path.getAbsolutePath(),mode,-1,-1); }
但是当我在文件浏览器中检查这些文件的权限时,它会显示“— rwx r-x”.
那么如何将权限设置为rw- r– r–?
解决方法@H_403_12@
Process process = null;
DataOutputStream dataOutputStream = null;
try {
process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
dataOutputStream.writeBytes("chmod 644 FilePath\n");
dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
} catch (Exception e) {
return false;
} finally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
process.destroy();
} catch (Exception e) {
}
}
Process process = null; DataOutputStream dataOutputStream = null; try { process = Runtime.getRuntime().exec("su"); dataOutputStream = new DataOutputStream(process.getOutputStream()); dataOutputStream.writeBytes("chmod 644 FilePath\n"); dataOutputStream.writeBytes("exit\n"); dataOutputStream.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (dataOutputStream != null) { dataOutputStream.close(); } process.destroy(); } catch (Exception e) { } }