VFS FileObject not able to delete file

900 views Asked by At

I have org.apache.commons.vfs.FileObject in my code and after the task is complete I need to delete the file. for which FileObject has delete () method. But it throws 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 .

1

There are 1 answers

0
devlover On

On checking file status, it was found not closed. So started working after closing the file

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