Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting Zip file to bytearray and vice versa

 
Alpesh Rathod
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I want to convert a zip file to byte array and then use that byte array to create a new zip file??

Please anyone how do i do it??
 
Niv Tyagi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Have you tried : java.util.zip.ZipInputStream

 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ZIP file does not need to be unzipped, so ZipInputStream is not necessary.

Use a FileInputStream to read the ZIP file and a ByteArrayOutputStream to write its contents to. Get the latter's byte[]. Use ByteArrayInputStream and FileOutputStream to reverse the process.
 
mahavir swami
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


so this will convert your zip entry into byte array

now you want this byte array gain to be written in zip so

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic