Reading files from a ZIP file in your Android assets folder

后端 未结 3 1731
挽巷
挽巷 2020-12-15 08:46

I\'m reading files from a ZIP file that\'s located in my Android assets folder using ZipInputStream: it works, but it\'s really slow, as it has to read it seque

3条回答
  •  离开以前
    2020-12-15 09:12

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

提交回复
热议问题