java - Can't delete file after it gets written -


i'll put code first:

@post public representation post(inputstream zip) throws throwable {     createfile(zip, "c:/temp");     return new stringrepresentation("file uploaded"); }      public void createfilee(inputstream zipstream, uploadedfilelocation) throws exception {     try {         writetofile(zipstream, uploadedfilelocation);         fileutils.forcedelete(new file(uploadedfilelocation));         } catch (exception e) {              throw e;         } }   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();         uploadedinputstream.close();     } catch (ioexception e) {         e.printstacktrace();     } } 

when send file server, cannot deleted. when using fileutils.forcedelete(), says cannot delete file. can delete file manually while server still running after tries delete file file utils. why can't delete itself?! ideas? thanks

edit: issue inputstream post alive until post returns? so, when call delete file, stream still kept alive post? possible?

in limited windows experience can 1 of 2 things

i check 1) anti-virus software trying scan file 2) kind of indexer (system or custom) trying index file.

you can use tool processexplorer see process holding file descriptor. http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -