简体   繁体   English

无法删除文件.file在Java TM SE库中打开

[英]File cannot be deleted .file is open in java tm SE library

Trying to upload a zipped multipart file. 尝试上传压缩的分段文件。 Writing in a particular location. 在特定位置书写。 But unable to delete the file. 但是无法删除文件。 After unzipping.. Tried using fileObj.delete but no use !! 解压缩后。。尝试使用fileObj.delete但没有用!

Just a sample code: 只是一个示例代码:

 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;

You must close the file when done with it. 完成后必须关闭文件。 Windows does not allow the deletion of open files. Windows不允许删除打开的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM