commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <ma...@ops.co.at>
Subject Re: [VFS] Exception while copying FileObject
Date Thu, 08 Dec 2005 07:42:02 GMT
Hi Eric!
> With commons-vfs RC6, I experience sometimes the following exception :
> Could not write to "file:///tmp/test/file3.txt" because it is read-only.
This again has something to do with the internal vfs cache.

>         throws Exception {
>         FileSystemManager fsManager = VFS.getManager();
>         FileObject        file1 = fsManager.resolveFile("/tmp/file1.txt");
>         FileObject        file2 = fsManager.resolveFile("/tmp/file2.txt");
>         new File("/tmp/test/").mkdirs();
>
>         FileObject file3 = fsManager.resolveFile("/tmp/test/file3.txt");
>         FileUtil.copyContent(file1, file3);
>         new File("/tmp/test/file3.txt").delete();
>         new File("/tmp/test/").delete();
>         new File("/tmp/test/").mkdirs();
>         file3 = fsManager.resolveFile("/tmp/test/file3.txt");
>   
file3.close();
>         FileUtil.copyContent(file2, file3);
>   
This will force vfs to refresh its internal states and then it works.

PS: instead of FileUtils you might use
file3.copyFrom(file2, Selectors.SELECT_SELF);
In your case it will do the same, but that way you can also copy 
directroies or apply a file filter ...

---
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message