简体   繁体   English

Java Files.copy抛出带有符号链接的FileNotFoundException

[英]Java Files.copy throws FileNotFoundException with Symbolic Links

I have code this code Files.copy(source, destination, options); 我有代码这段代码Files.copy(source, destination, options); which should copy any file from source to destination. 应该将任何文件从源复制到目标。 However, when it encounters a symbolic link. 但是,当它遇到符号链接时。 I get FileNotFoundException 我得到FileNotFoundException

What is going on? 到底是怎么回事? Why is this happening? 为什么会这样呢?

The problem I had was that while copying files, it was attempting to follow the symlink file and copy that as well, however, it didn't find the original file. 我遇到的问题是,在复制文件时,它试图跟随符号链接文件并进行复制,但是,它没有找到原始文件。 That is why it is throwing a FileNotFoundException . 这就是为什么它抛出FileNotFoundException

As a fix I used this: LinkOption.NOFOLLOW_LINKS as an option and it worked fine. 作为修复,我使用了以下方法: LinkOption.NOFOLLOW_LINKS作为一个选项,它运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM