1. import net.lingala.zip4j.model.FileHeader;
  2. import net.lingala.zip4j.ZipFile;
  3. import net.lingala.zip4j.exception.ZipException;
  4. import java.io.InputStream;
  5. import java.io.IOException;
  6. import java.io.BufferedInputStream;
  7. import java.io.ByteArrayOutputStream;
  8. public class SampleClass{
  9. public static void main(String[] args)
  10. throws ZipException,
  11. IOException{
  12. ZipFile zip = null;
  13. try{
  14. zip = new ZipFile
  15. ("myzip.zip");
  16. FileHeader header =
  17. zip.getFileHeader("img.jpg");
  18. try(BufferedInputStream bif =
  19. new BufferedInputStream(zip.getInputStream(header));
  20. ByteArrayOutputStream baos =
  21. new ByteArrayOutputStream()){
  22. bif.transferTo(baos);
  23. for(byte b : baos.toByteArray())
  24. System.out.print(b + " ");
  25. }
  26. }
  27. finally{
  28. if(zip != null)
  29. zip.close();
  30. }
  31. }
  32. }