java: Flush stream while creating zip file -
i have code create zip file in servlet :
bytearrayoutputstream baos =null; baos = new bytearrayoutputstream(); zipoutputstream zos = new zipoutputstream(baos); for(list of file){ bis = new bufferedinputstream(new fileinputstream(("somefile.extn")); other code add entry in zip file bis.close(); } baos.flush(); zos.flush(); zos.close(); baos.close(); // return bytes baos.tobytearray(); // write bytes servletoutputstream
is there problem if flush & close bytearrayoutputstream
object (baos
).
thanks looking here :)
it redundant. need is
zos.close();
closing zipoutputstream
flushes , closes other streams wrapped around. see javadoc.
you don't need bytearrayoutputstream.
should connect zipoutputstream
directly servlet output stream.
Comments
Post a Comment