Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Zip File to Byte Array  RSS feed

 
monnlq
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, how can i convert a Zip file into a Byte Array and vice versa..........i'm trying to send the zip file using web services to a mobile device, thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This belongs in our I/O forum; I'll move it there for you.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a zip file on disk, get the size using java.io.File.length(), allocate a byte array "buffer" of that size, open the file with FileInputStream, call read(buffer), close the FileInputStream.

If you have a byte array, open the file with a FileOutputStream, call write(byteArray), close the FileOutputStream.

Here is a fine tutorial on Java I/O.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!