我在使用名称包含'&'的远程Windows共享操作时遇到问题。通过apache-camel使用jcifs的角色。其根本原因在于显然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.
我可以简单地更改目录名称,但也许有人知道更好的方法。如果要改变它会怎么样?
答案 0 :(得分:0)
在重命名
之前尝试关闭输出流smbFile.getOutputStream()