Android Question Unzip single file from 7z archive

bernardR

Member
Licensed User
Longtime User
Hello,
I have a 7z archive containing 100 files named 1.txt, 2.txt, ..., 100.tx
I want to extract only the file 5.txt
Is it possible?
In the existing libraries I have not found an example for the extraction of a single file.
Thank you
 

agraham

Expert
Licensed User
Longtime User
According to Wikipedia
7z cannot give the start of the files within the archive—it must wait until all segments are downloaded.
So it looks like you need to decompress the whole archive then delete the files you don't want.
 
Upvote 1

drgottjr

Expert
Licensed User
Longtime User
it is possible to extract a single file from a .7z archive. files in an archive are
referred to as "entries". a .7z parser must read through the entries to search for
a given entry. entry metadata will include - among others - the entry size in bytes.
a parser can rapidly skip from one entry to the next. when a match is found, the
desired file can be extracted and saved. in other words, the parser does not need
to extract and save all the entries in the event the user only wants one entry.

i can extract a single file using inline java with apache.commons.compress, but
creating a library with slc produces the annoying "file name or extension too long"
error. at least with apache.commons. there are other java libraries out there.
perhaps one of the other libraries suits slc better, in case someone is interested.
the basic plan is simple enough and is as described above. it's basically the same
as with .zip files (for which there is a standard java class), the same except you
have to use a 3rd party library.
 
Upvote 0
Top