I have a zip file created by my Android application on the tablet I am also using for tests later. I can open it on the Android tablet and also on my PC, i.e. it is not corrupted. I added this .zip file to /res/raw folder of my Android test project. Now I would like to copy this file for one of my junit testcases to Android device. For that, I use the following code:
boolean success = false;
File appDirectory = MainActivity.getContext().getExternalFilesDir(null);
File pictureSketch = new File(appDirectory, sketchName+".zip");
if (!appDirectory.exists()) {
assertTrue("App directory could not be created.",appDirectory.mkdirs());
}
InputStream in = activity.getResources().openRawResource(raw.pictest);
FileOutputStream out = new FileOutputStream(pictureSketch);
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();
success = true;
}
return success;
The zip file with the correct file is created, but when opened, it gives an error message: bad zip file. What should I change for being able to open the zip file after the transfer?