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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -