在应用程序中更改文件权限 [英] Change file permission in application

查看:150
本文介绍了在应用程序中更改文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更改文件权限的应用程序。 code是如下:

 调用Runtime.getRuntime()EXEC(搭配chmod 777 /sdcard/test.txt)。
 

这code。在我的应用程序不工作,但没有错误日志。 我也查壳工具在/系统/ bin中,找到文件模式下/系统/箱,但表现出来的其他一些信息的文件模式>工具箱。我并不清楚这一点。我的应用程序使用的Andr​​oid版本:sharedUserId =android.uid.system。 如何运行此code或如何改变文件的访问权限?多谢。

解决方案

 运行RT =调用Runtime.getRuntime();
流程PROC;
尝试 {
    PROC = rt.exec(新的String [] {苏,-c,文件模式777+ Constants.filename});
    proc.waitFor();
}赶上(例外五){// DOSTUFFS}
 

这应该做的伎俩

I try to change file permission in application. Code is below:

Runtime.getRuntime().exec("chmod 777 /sdcard/test.txt");

This code NOT works in my application, but no error log. I also checked the shell tools under /system/bin, find chmod is under /system/bin, but some other info shown that chmod > toolbox. I am not clear about this. My application has used android:sharedUserId="android.uid.system". How to run this code or how to change permission of file? Thanks a lot.

解决方案

Runtime rt = Runtime.getRuntime();
Process proc;
try {
    proc = rt.exec(new String[] { "su", "-c", "chmod 777 " + Constants.filename });
    proc.waitFor();
} catch (Exception e){ //DOSTUFFS }

This should do the trick

这篇关于在应用程序中更改文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆