IE浏览文件后无法删除文件夹,但可以删除文件

时间:2014-01-27 16:52:28

标签: java windows internet-explorer apache-commons-fileupload

使用IE上传文件后无法删除文件所在的文件夹,但可以删除该文件。通过Firefox上传后没问题。如何解锁目录?

我的代码:

DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
List<FileItem> uploadedItems = servletFileUpload.parseRequest(request);
if (uploadedItems != null && !uploadedItems.isEmpty()) {
    FileItem fileItem = uploadedItems.get(0);
    InputStream is = fileItem.getInputStream();
    long jobId = importService.importFileAsync(is, fileItem.getName());
    is.close();
    return jobId;
}

我用importFileAsync方法:

public long importFileAsync(final InputStream inputStream, final String fileName) {
    Job job = new Job() {

        @Override
        protected void compute() throws ApplicationException {
            try (InputStreamReader inputReader = new InputStreamReader(inputStream, "UTF-8")){
                    //processing of data from file
            } catch(Exception e){
                    //processing of exception
            }
        }
    }   
    ...
}

1 个答案:

答案 0 :(得分:0)

如果你使用Apache Commons IO,它就是一个单行:

FileUtils.deleteDirectory(dir);

See FileUtils.deleteDirectory()