- import net.lingala.zip4j.model.FileHeader;
- import net.lingala.zip4j.ZipFile;
- import net.lingala.zip4j.exception.ZipException;
- import java.io.InputStream;
- import java.io.IOException;
- import java.io.BufferedInputStream;
- import java.io.ByteArrayOutputStream;
-
- public class SampleClass{
-
- public static void main(String[] args)
- throws ZipException,
- IOException{
- ZipFile zip = null;
-
- try{
- zip = new ZipFile
- ("myzip.zip");
- FileHeader header =
- zip.getFileHeader("img.jpg");
-
- try(BufferedInputStream bif =
- new BufferedInputStream(zip.getInputStream(header));
- ByteArrayOutputStream baos =
- new ByteArrayOutputStream()){
-
- bif.transferTo(baos);
- for(byte b : baos.toByteArray())
- System.out.print(b + " ");
-
- }
- }
- finally{
- if(zip != null)
- zip.close();
- }
- }
- }