关于android源码文件操作,无权限问题

1 篇文章 0 订阅
1 篇文章 0 订阅

针对linux系统


  1. 直接使用“su“命令,提高所操作文件权限即可

针对于anroid/java代码中需要改变某些文件的权限,例如读写权限,操作权限等的使用方式(相当如如何java调用linux命令)


public static String exec(String cmd) {
        try {
            if (cmd != null) {
                Runtime rt = Runtime.getRuntime();
                Process process = rt.exec("su");//Root   //Process process = rt.exec("sh");//
                DataOutputStream dos = new DataOutputStream(process.getOutputStream());
                dos.writeBytes(cmd + "\n");
                dos.flush();
                dos.writeBytes("exit\n");
                dos.flush();
                InputStream myin = process.getInputStream();
                InputStreamReader is = new InputStreamReader(myin);
                char[] buffer = new char[1024];
                int bytes_read = is.read(buffer);
                StringBuffer aOutputBuffer = new StringBuffer();
                while (bytes_read > 0) {
                    aOutputBuffer.append(buffer, 0, bytes_read);
                    bytes_read = is.read(buffer);
                }
                Log.e(TAG, aOutputBuffer.toString());
                return aOutputBuffer.toString();
            } else {
                return "please input true cmd";
            }
        } catch (IOException e) {
            e.printStackTrace();
            return "operater err";
        }
    }

使用方式

ChangeBuildPropTools.exec("chmod -R 777" + EMAIL_SEAFILE_PATH);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值