i have a code that takes a file, zip it, and stores it in a database
looks like this
// STEP 1 - Create a ZIP file
byte[] buffer = new byte[1024];// 18024
ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream("file.zip"));
outZip.setLevel(Deflater.DEFAULT_COMPRESSION);
FileInputStream in = new FileInputStream(c:\file.hex);
outZip.putNextEntry(new ZipEntry("file.hex"));
int len;
while (( len = in.read(buffer)) > 0)
outZip.write(buffer, 0, len);
outZip.closeEntry();
in.close();
outZip.close();
// STEP 2 - Insert zip file to DB
file = new File("file.zip");
FileInputStream fis = new FileInputStream( file );
the fis object i store in the DB
but i would like to avoid the filesystem completely , and not create the file.zip. i think i need to convert the ZipOutputStream into FileInputStream directly but i could not find a way to do it.
is there an easy way to accomplish this ?
- i also have the same problem when i extract the file, in order to read it i must create 2 different temporary files - file.zip and file.hex