我正在尝试在android11 11/12中将文件从raw复制到/system/bin/ location。
请查找以下代码:
舱单许可:
<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) {
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 (只读文件系统)
发布于 2022-08-02 11:21:52
尝试新文件(“/system/bin”).exists()。
尝试新文件(“/system/bin”).canRead()。
尝试新文件(“/system/bin”).canWrite()。
在你尝试其他事情之前。
https://stackoverflow.com/questions/73205258
复制相似问题