Convert bytes to File and zip it into a folder using Java in Spring -
i'm trying generate pdf , works fine i'm flushing out bytes browser. now, scenario changed. there multiple files now, how can create these bytes , put in single zip folder , flush it. tried google it, of sites take me create zip stream of file.
business logic
string[] documents = {"2","3","4","5"}; servletoutputstream out = response.getoutputstream(); (string documentkey: documents) { if(tkey!= null && !tkey.isempty() && documentkey != null && !documentkey.isempty()) { byte[] documentbytes = myservice.generatedocument(tkey, documentkey); writebytestofile(documentbytes,); --> how can mention file name here? string documenttype = myutil.getdocumenttype(documentkey); response.setheader("content-disposition", "attachment;filename="+documenttype); response.setcontenttype("application/pdf"); response.setheader("expires", "0"); response.setheader("cache-control", "must-revalidate, postcheck=0, pre-check=0"); response.setheader("pragma", "public"); response.setcontentlength(documentbytes.length); out.write(documentbytes); out.flush(); out.close(); logger.debug("********** document generated **********"); } } another method in same class
public void writebytestofile(byte[] bfile, string filedest) { try (fileoutputstream fileouputstream = new fileoutputstream(filedest)) { fileouputstream.write(bfile); } catch (ioexception e) { e.printstacktrace(); } } the bytes should converted file initially. but, how can know file destination? should done automatically. file name can kept 1.pdf,2.pdf,3.pdf,4.pdf
i need these 4 files should kept under folder , gets flushed
how can put these documents in zip folder , downloaded?
Comments
Post a Comment