当通过apache-camel使用jcif在名称包含'&‘字符的远程Windows共享上操作时,我遇到了一个问题。根本原因是jcifs在重命名远程文件时不能很好地处理'&‘字符,而Windows在这方面没有问题。
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)
jcifs.smb.SmbException: The process cannot access the file because it is being used by another process.我可以简单地更改目录名,但也许有人知道更好的方法。如果它很难改变呢?
发布于 2015-03-31 18:43:21
在重命名前尝试关闭输出流smbFile.getOutputStream()
https://stackoverflow.com/questions/28101045
复制相似问题