Java FileUtils.copyFile()在目标为网络路径时不创建文件(在windows上)
我正在使用apache common将本地磁盘上的文件复制到网络共享位置。共享文件夹已存在,并且运行应用程序的用户具有访问该文件夹的权限。copyFile()执行时没有异常。但是,实际上并没有创建该文件Java FileUtils.copyFile()在目标为网络路径时不创建文件(在windows上),java,windows,apache-commons-io,Java,Windows,Apache Commons Io,我正在使用apache common将本地磁盘上的文件复制到网络共享位置。共享文件夹已存在,并且运行应用程序的用户具有访问该文件夹的权限。copyFile()执行时没有异常。但是,实际上并没有创建该文件 File sourceFile = new File ("C:\\sourcefile.txt"); File destinationFile = new File("\\data-server\\my_share\\dest.txt"); // false System.out.println
File sourceFile = new File ("C:\\sourcefile.txt");
File destinationFile = new File("\\data-server\\my_share\\dest.txt");
// false
System.out.println("Before copy, file exists? " + destinationFile.exists());
FileUtils.copyFile(sourceFile, destinationFile);
// true
System.out.println("After copy, file exists? " + destinationFile.exists());
如果将网络共享路径指定为目标,则该路径不起作用。但是,如果我在windows中映射网络驱动器并通过网络映射对其进行写入,它就会工作。非常奇怪的是,我在复制操作后调用file.exists(),java报告该文件存在,但它没有显示
我还尝试使用FIleUtils.copyFileToDirectory(),只指定目标目录而不是文件名。当目标是网络路径时,我也遇到同样的问题。您的目标需要额外的转义字符
"\\\\data-server\\my_share\\dest.txt"
这是正确的。但是,我仍然很困惑为什么会有报告说文件是创建的。它可能是在当前驱动器的根目录下创建的。在c:\data server\my_share\dest.txtYes下查找,刚刚找到。你说得对。嗯,那太令人兴奋了!