0

I have tried two methods

METHOD 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);
    }
}

in the above method i am getting /system/app/filename: open failed: EROFS (Read-only file system) error

METHOD 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());
    }

 }

using this method the file is copied but becomes corrupted

Note: 1.I have rooted the device first 2.I am using root tool library to remount system folder rw permission

neha
  • 43
  • 1
  • 1
  • 4
  • See [this](http://stackoverflow.com/a/4530294/1432752) answer – pawegio Oct 17 '16 at 11:25
  • In theory, you could copy the file from assets to a regular file (e.g., in `getCacheDir()`), then copy/move the file into position on the system partition. – CommonsWare Oct 17 '16 at 11:45
  • Thanks @CommonsWare Now i have solved this problem by merging the above code First i copied the file in external folder and then used the second method to copy from that folder to system – neha Oct 20 '16 at 04:51
  • Now i am getting file checksum error. MD5 and SHA 1 calculation failed when file copied to system folder . How to copy file with MD5 and SHA 1 information in system folder – neha Oct 20 '16 at 04:54

0 Answers0