[jcifs] Getting concurrency error when deleting a file

Michael B Allen ioplex at gmail.com
Tue Mar 3 01:52:49 GMT 2009

On Mon, Mar 2, 2009 at 1:46 PM, Hugo Palma <hugo.m.palma at gmail.com> wrote:
> Hi all,
> a have a very simple use case where i want to get all the file in a
> directory, iterate over them a delete a few.
> My code is something like:
> SmbFile folder = new SmbFile("smb://myfolder");
> for (SmbFile file : folder.listFiles()) {
>     // do something
>    file.delete();
> }
> It seems that if that "do something" doesn't include calling the
> "getInputStream" method on the file everything goes fine. But if it does i
> get the following error on the delete operation:

I would think that that should still work since I thought
getInputStream opened the file with a permissible shareAccess. Perhaps

Anyway, try calling close() on the InputStream before you delete().


> jcifs.smb.SmbException: The process cannot access the file because it is
> being used by another process.
>         at
> jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:522)
>         at
> jcifs.smb.SmbTransport.send(SmbTransport.java:622)
>         at
> jcifs.smb.SmbSession.send(SmbSession.java:239)
>         at
> jcifs.smb.SmbTree.send(SmbTree.java:109)
>         at
> jcifs.smb.SmbFile.send(SmbFile.java:718)
>         at
> jcifs.smb.SmbFile.delete(SmbFile.java:2342)
>         at jcifs.smb.SmbFile.delete(SmbFile.java:2286)
> Any idea why this is happening ? Clearly some resource if being left open
> but i don't see any close method.
> Thanks

Michael B Allen
Java Active Directory Integration

More information about the jcifs mailing list