is it possible to open zip file and acts with it as it was a folder. I need to do partial unzip of one folder inside ZIP file from hunders at a time. Standard iteration through is wery slow (presuming I need to open folder with ID=432, so 431 folders will be checked before). Is there any approach I can partially and quickly unzip some data from zip?
Thanks
see this example it may help to you .
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
System.out.println("^^^^^^UnzippingFile^"+ze.getName());
///code to search is given string exists or not in a Sentence
String haystack = ze.getName();
String needle1 = ".DS_Store";
int index1 = haystack.indexOf(needle1);
if (index1 != -1)
{
System.out.println("The string contains the substring "
+ needle1);
continue;
}
/*else
System.out.println("The string does not contain the
substring " + needle1);*/
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location +
ze.getName());
// replace for loop with:
byte[] buffer = new byte[1024];
int length;
while ((length = zin.read(buffer))>0) {
fout.write(buffer, 0, length);
}
zin.closeEntry();
fout.close();
}
}////Outer While
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
Take a look at getEntry
method on ZipFile
here.