Reading files from a ZIP file in your Android assets folder

后端 未结 3 1738
挽巷
挽巷 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:23

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

提交回复
热议问题