首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JCIFS jcifs.smb.SmbFile#renameTo不喜欢像'&‘这样的特殊字符

JCIFS jcifs.smb.SmbFile#renameTo不喜欢像'&‘这样的特殊字符
EN

Stack Overflow用户
提问于 2015-01-23 08:19:14
回答 1查看 1.2K关注 0票数 0

当通过apache-camel使用jcif在名称包含'&‘字符的远程Windows共享上操作时,我遇到了一个问题。根本原因是jcifs在重命名远程文件时不能很好地处理'&‘字符,而Windows在这方面没有问题。

代码语言:javascript
复制
public class SmbFileTest {

    @Test
    public void testAmperstand() throws Exception {
        String targetLocation = "smb://user:pass@host/share/hello&goodbye";
        SmbFile targetLocationFile = new SmbFile(targetLocation);
        if(!targetLocationFile.exists()){
            targetLocationFile.mkdirs();
        }
        SmbFile smbFile = new SmbFile(targetLocation+"/to.tmp");
        IOUtils.write("content",smbFile.getOutputStream());
        SmbFile smbFileDest = new SmbFile(targetLocation+"/to.txt");
        smbFile.renameTo(smbFileDest);
    }
}

上述测试失败(jcifs 1.3.17 <= camel 2.12.1)

代码语言:javascript
复制
jcifs.smb.SmbException: The process cannot access the file because it is being used by another process.

我可以简单地更改目录名,但也许有人知道更好的方法。如果它很难改变呢?

EN

回答 1

Stack Overflow用户

发布于 2015-03-31 18:43:21

在重命名前尝试关闭输出流smbFile.getOutputStream()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28101045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档