dynamic - Is there any way to create zip in a zip file using java dynamically..? -


i have bunch of files, 4 files.. want zip 2 files zip "inner.zip" , rest parent directory of "outer.zip".

i.e

enter image description here

inputstream streamtoreadfile=readfile(filepath); string zipentryname = foldername + "/" + filenametowrite; zipentry anentry = new zipentry(zipentryname);  // couldn't able create zip in zip file.  streamtowriteinzip.putnextentry(anentry); while ((bytesin = streamtoreadfile.read(readbuffer)) > 0) {                     streamtowriteinzip.write(readbuffer, 0, bytesin);                 } 

the inner zipoutputstream should call finish() instead of close() finish() flushes compressed data, not close outer zip. mind test erroneousness of close() 1 need add yet file, inner zip last.

    path sourcepath = paths.get("c:/d/test.html");     try (zipoutputstream zipout = new zipoutputstream(             new fileoutputstream("c:/d/test/test.zip"))) {          zipout.putnextentry(new zipentry("file1.txt"));         files.copy(sourcepath, zipout);         zipout.closeentry();          zipout.putnextentry(new zipentry("file2.txt"));         files.copy(sourcepath, zipout);         zipout.closeentry();          zipout.putnextentry(new zipentry("inner.zip"));         zipoutputstream innerzipout = new zipoutputstream(zipout);         {             innerzipout.putnextentry(new zipentry("file3.txt"));             files.copy(sourcepath, innerzipout);             innerzipout.closeentry();              innerzipout.putnextentry(new zipentry("file4.txt"));             files.copy(sourcepath, innerzipout);             innerzipout.closeentry();              innerzipout.finish(); // instead of close().         }         zipout.closeentry();      } catch (ioexception e) {         e.printstacktrace();     } // invoke close(). 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -