2012-04-02 65 views
0

試圖上傳壓縮的多部分文件。寫在一個特定的位置。但無法刪除該文件。解壓後..嘗試使用fileObj.delete但沒用!文件無法刪除.file在java tm SE庫中打開

只是一個示例代碼:

DiskFileItemFactory factory = new DiskFileItemFactory(); 
     factory.setSizeThreshold(maxMemSize); 

     // Create a new file upload handler 
     ServletFileUpload upload = new ServletFileUpload(factory); 
     upload.setSizeMax(maxFileSize); 
     List fileItems = upload.parseRequest(request); 

     // Process the uploaded file items 
     Iterator i = fileItems.iterator(); 
     while (i.hasNext()) 
     { 
      FileItem fi = (FileItem) i.next(); 
      if (!fi.isFormField()) 
      { 
       fileName = FilenameUtils.getName(fi.getName()); 
       String contentType = fi.getContentType(); 
       long sizeInBytes = fi.getSize(); 
       logger.info("File name is::"+fileName); 
       logger.info("content type is ::"+ contentType); 
       logger.info("size is::"+sizeInBytes); 

       // Write the file 

       fileObj = new File(dirObj, clientFileName+".zip"); 
       fi.write(fileObj); 
    return fileObj; 

回答

0

時用它做你必須關閉文件。 Windows不允許刪除打開的文件。