Posted By

Caliban on 11/29/06


Tagged

file zip ByteArrayOutputStream


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

indianocean


Extract ZipEntry into a ByteArrayOutputStream


 / Published in: Java
 

  1. import java.io.ByteArrayOutputStream;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.util.zip.InflaterInputStream;
  7. import java.util.zip.ZipEntry;
  8. import java.util.zip.ZipInputStream;
  9.  
  10.  
  11. public class ZipInputStreamTest
  12. {
  13.  
  14. /**
  15.   * @param args
  16.   * @throws IOException
  17.   */
  18. public static void main( String[] args ) throws IOException
  19. {
  20. FileInputStream file = new FileInputStream( "C:\\Test.zip" );
  21. ZipInputStream zip_inputstream = new ZipInputStream( file );
  22.  
  23. ZipEntry current_zip_entry = null;
  24.  
  25. while( ( current_zip_entry = zip_inputstream.getNextEntry() ) != null )
  26. {
  27. System.out.println( current_zip_entry.getName() );
  28.  
  29. int data = 0;
  30. while( ( data = zip_inputstream.read() ) != - 1 )
  31. {
  32. output.write( data );
  33. }
  34.  
  35. // The ZipEntry is extracted in the output
  36. output.close();
  37. }
  38.  
  39. zip_inputstream.close();
  40. file.close();
  41. }
  42.  
  43. }

Report this snippet  

You need to login to post a comment.