简体   繁体   English

VFS FileObject 无法删除文件

[英]VFS FileObject not able to delete file

I have org.apache.commons.vfs.FileObject in my code and after the task is complete I need to delete the file.我的代码中有 org.apache.commons.vfs.FileObject ,任务完成后我需要删除该文件。 for which FileObject has delete () method. FileObject 有 delete() 方法。 But it throws FileSystemException.但它会抛出 FileSystemException。

I did check if there there is file exist, and further delete the file.我确实检查了是否存在文件,并进一步删除了该文件。

FileObject doc2Delete = VFS.getManager().resolveFile("C:\test.pdf");
if (doc2Delete.exists()) {
try {
doc2Delete.delete();
} catch (FileSystemException fse) {
fse.printStackTrace();
}

I expect the file to be deleted but it throws FileSystemException.我希望该文件被删除,但它会引发 FileSystemException。

On checking file status, it was found not closed.在检查文件状态时,发现它没有关闭。 So started working after closing the file所以关闭文件后开始工作

if(doc2Delete.isContentOpen()){
doc2Delete.close()
}

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

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