首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将文件复制到/system/bin/ in android11 11/12

将文件复制到/system/bin/ in android11 11/12
EN

Stack Overflow用户
提问于 2022-08-02 09:37:28
回答 1查看 127关注 0票数 0

我正在尝试在android11 11/12中将文件从raw复制到/system/bin/ location。

请查找以下代码:

舱单许可:

代码语言:javascript
复制
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

MainActivity:

保护空洞onCreate(Bundle savedInstanceState) {

代码语言:javascript
复制
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    YourFile(R.raw.test);
}

private void YourFile(int Resource) {

    String pathSystemBin = "/system/bin"+ "/test_new"; // File path


    try{
        InputStream in = getResources().openRawResource(Resource);
        FileOutputStream out = null;
        out = new FileOutputStream(pathSystemBin);
        byte[] buff = new byte[1024];
        int read = 0;
        try {
            while ((read = in.read(buff)) > 0) {
                out.write(buff, 0, read);
            }
        } finally {
            in.close();
            out.close();
            end();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

private void end () {
    Toast.makeText(MainActivity.this,"File saved",Toast.LENGTH_LONG).show();
}

出现以下错误:

W/System.err: java.io.FileNotFoundException: /system/bin/test _new :打开失败: EROFS (只读文件系统)

EN

回答 1

Stack Overflow用户

发布于 2022-08-02 11:21:52

尝试新文件(“/system/bin”).exists()。

尝试新文件(“/system/bin”).canRead()。

尝试新文件(“/system/bin”).canWrite()。

在你尝试其他事情之前。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73205258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档