java - In Android, is it necessary to loop through all files/directories in a zip to read content from a file at known location? -
i want read first line of file within zip file. using while loop 1 sample stackoverflow quesion link
but know exact location of file within zip. , zip file big(can more 500mb).
so i'm thinking there way read file without looping through files using while.
use zipfile
instead of zipinputstream
. reads zip file's central directory (see wikipedia article) , not whole file. can utilize entries()
or getentry(java.lang.string)
, getinputstream(java.util.zip.zipentry)
input stream entry:
string entryname = // set name of entry here file file = // set zip file here zipfile zipfile = null; seek { zipfile = zipfile(file); zipentry zipentry = zipfile.getentry(entryname); inputstream = null; seek { = zipfile.getinputstream(zipentry); // read stream here e.g. using bufferedreader } grab (ioexception ex) { // todo: handle exception or delete grab block } { if (is != null) { seek { is.close(); } grab (ioexception ex) { } } } } { if (zipfile != null) { zipfile.close(); } }
java android file file-io zip
No comments:
Post a Comment