java copyfile失败_java – FileUtils.copyFile()在目标是网络路径时不创建文件(在Windows上)...

我正在使用apache common的FileUtils.copyFile()将本地磁盘上的文件复制到网络共享位置.共享文件夹已存在,运行该应用程序的用户具有该权限. FileUtils.copyFile()执行时没有异常.但是,该文件实际上并未创建.

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"

标签:java,windows,apache-commons-io

来源: https://codeday.me/bug/20190829/1764722.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值