Reading files from a ZIP file in your Android assets folder
This works for me:
private void loadzip(String folder, InputStream inputStream) throws IOException{ ZipInputStream zipIs = new ZipInputStream(inputStream); ZipEntry ze = null; while ((ze = zipIs.getNextEntry()) != null) { FileOutputStream fout = new FileOutputStream(folder +"/"+ ze.getName()); byte[] buffer = new byte[1024]; int length = 0; while ((length = zipIs.read(buffer))>0) { fout.write(buffer, 0, length); } zipIs.closeEntry(); fout.close(); } zipIs.close();}
You can create a ZipInputStream in the following way :
ZipInputStream zipIs = new ZipInputStream(context.getResources().openRawResource(your.package.com.R.raw.filename)); ZipEntry ze = null; while ((ze = zipIs.getNextEntry()) != null) { FileOutputStream fout = new FileOutputStream(FOLDER_NAME +"/"+ ze.getName()); byte[] buffer = new byte[1024]; int length = 0; while ((length = zipIs.read(buffer))>0) { fout.write(buffer, 0, length); } zipIs .closeEntry(); fout.close(); } zipIs .close();