I am trying to get only one file (I know its name) from a very large zip archive. This archive includes about 100,000 files because I do not want to find my file in a loop. I think it should be some kind of solution for this case, something like a command on Linux.
unzip archive.zip myfile.txt
I wrote the following code
try { FileInputStream fin = new FileInputStream(rootDir+"/archive.zip"); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = new ZipEntry("myfile.txt"); FileOutputStream fout = new FileOutputStream(rootDir+"/buff/" + ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); zin.close(); } catch(Exception e) { Log.e("Decompress", "unzip", e); }
This code creates a new file in the buff directory, but this file is empty! Please help me with this problem!
Thank you for your time!
source share