I am trying to write an apk to /system/app location in Android Emulator. Here is my code:
File path = Environment.getRootDirectory();
File fileToWrite = new File(path, "/" + fileName);
byte[] buff = new byte[1024];
int l = 0;
// write buffer to file
FileOutputStream fos = new FileOutputStream(fileToWrite);
while((l = zis.read(buff)) > 0){
fos.write(buff,0, l);
}
fos.close();
My AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
However, I am getting these error message:
java.io.FileNotFoundException: /system/MainApp-debug.apk (Read-only file system) 06-08 08:51:59.858 2921-3160/com.mainapp W/System.err: at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:287)
I managed to write to /mnt/sdcard/Download
folder using the same code. But I not sure why it is not able to write to /system/app
folder.
Any ideas? Thanks!