Should inputstream be closed explicitly when uploading file in jersey multipart? -


i use jersey multipart upload file in controller

here typical code case:

@path("/file") public class uploadfileservice {      @post     @path("/upload")     @consumes(mediatype.multipart_form_data)     public response uploadfile(         @formdataparam("file") inputstream uploadedinputstream,         @formdataparam("file") formdatacontentdisposition filedetail) {          string uploadedfilelocation = "d://uploaded/" + filedetail.getfilename();          // save         writetofile(uploadedinputstream, uploadedfilelocation);          string output = "file uploaded : " + uploadedfilelocation;          return response.status(200).entity(output).build();      }      // save uploaded file new location     private void writetofile(inputstream uploadedinputstream,         string uploadedfilelocation) {          try {             outputstream out = new fileoutputstream(new file(                     uploadedfilelocation));             int read = 0;             byte[] bytes = new byte[1024];              out = new fileoutputstream(new file(uploadedfilelocation));             while ((read = uploadedinputstream.read(bytes)) != -1) {                 out.write(bytes, 0, read);             }             out.flush();             out.close();         } catch (ioexception e) {              e.printstacktrace();         }      }  } 

i have read many example code online, , inputstream not closed.

my question should close uploadedinputstream explicitly or manually? , why?


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -