2013年9月6日星期五

COS upload a file to the tomcat can not delete

COS upload a file to the tomcat can not be deleted , restart the tomcat and they can be deleted. Seek help on how to solve the tomcat cos uploaded files occupancy , thank
------ Solution -------------------------- ------------------
file stream is not closed , resulting in a paper to be occupied.
------ For reference only -------------------------------------- -
speed really fast , thank you . I checked under the API documentation to see
------ For reference only ------------------------------- --------
I use this constructor
: MultipartRequest (javax.servlet.http.HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize, FileRenamePolicy policy)
in my code is : MultipartRequest mulit = new MultipartRequest (request, filePath, fileMaxSize, "UTF-8", rfrp);

This mulit not close stream.
The link is this constructor source : http://grepcode.com/file/repo1.maven.org/maven2/com.servlets/cos/05Nov2002/com/oreilly/servlet/MultipartRequest.java/ # MultipartRequest.% 3Cinit% 3E% 28com.oreilly.servlet.HttpServletRequest% 2Cjava.lang.String% 2Cint% 2Ccom.oreilly.servlet.multipart.FileRenamePolicy% 29
Does anyone have other recommendations
------ For reference only --------------------------- ------------
from the above source , filePart.writeTo (dir); this method View writeTo (); see
public long writeTo (File fileOrDirectory) throws IOException {
long written = 0;

OutputStream fileOut = null;
try {
/ / Only do something if this part contains a file
if (fileName! = null) {
/ / Check if user supplied directory
File file;
if (fileOrDirectory.isDirectory ()) {
/ / Write it to that dir the user supplied,
/ / with the filename it arrived with
file = new File (fileOrDirectory, fileName);
}
else {
/ / Write it to the file the user supplied,
/ / ignoring the filename it arrived with
file = fileOrDirectory;
}
if (policy! = null) {
file = policy.rename (file);
fileName = file.getName ();
}
fileOut = new BufferedOutputStream (new FileOutputStream (file));
written = write (fileOut);
}
}
finally {
if (fileOut! = null) fileOut.close ();
}
return written;
}

also closed the file stream , this problem does not appear to use jspSmart Yeah , still can not find where to doubt

没有评论:

发表评论