我尝试了两种方法
方法1
private void CopyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("myfoldername");
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
RootTools.remount("/system/app/", "rw");
in = assetManager.open("myfoldername/"+filename);
out = new FileOutputStream("/system/app/" + filename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) {
Log.e("tag", e.getMessage());
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
在上面的方法中我得到 / system / app / filename:open failed:EROFS(只读文件系统)错误
方法2:
private void method_to_copy(String app,String localFolder)
{
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list(localFolder);
for(int i=0;i<files.length;i++){
RootTools.remount("/system/app/", "rw");
Runtime.getRuntime().exec("su cat " + "localFolder/" + files[i] + " > " + "/system/" + systemFolder+"/"+ files[i] );
}
} catch (IOException e) {
Log.w("tag", e.getMessage());
}
}
使用此方法复制文件但损坏
注意: 我先把设备扎根了 2.我正在使用根工具库来重新安装系统文件夹rw权限