当目标是网络路径时(在Windows上)FileUtils.copyFile()不创建文件 [英] FileUtils.copyFile() not creating file when destination is a network path (on windows)

查看:509
本文介绍了当目标是网络路径时(在Windows上)FileUtils.copyFile()不创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache common的

I'm using apache common's FileUtils.copyFile() to copy a file on a local disk to a network share location. The shared folder already exists, and the user running the app has permission to it. FileUtils.copyFile() executes with no exceptions. However, the file doesn't actually get created.

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报告该文件存在,但是没有显示出来.

With the network share path specified as the destination, it doesn't work. But, if I map the network drive in windows and write to it via the network map, it works. What's very odd is that I call file.exists() after the copy operation, and java reports that the file exists, but it doesn't show up.

我还尝试使用FIleUtils.copyFileToDirectory(),仅指定目标目录而不是文件名.当目标是网络路径时,我也遇到同样的问题.

I also tried using FIleUtils.copyFileToDirectory(), just specifying the destination directory and not the file name. I'm getting the same issue when the destination is the network path.

推荐答案

您的目的地需要其他转义字符.

Your destination needs additional escape characters.

"\\\\data-server\\my_share\\dest.txt"

这篇关于当目标是网络路径时(在Windows上)FileUtils.copyFile()不创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆