本文介绍了当我复制两个空路径,为什么不抛出异常呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  scala> import java.nio.file._ 
import java.nio.file._

scala> Files.copy(Paths.get(),Paths.get())
res0:java.nio.file.Path =

不应该抛出 NoSuchFileException



显示:

但是我不确定这是真正的原因,因为 Files.copy(Paths.get a),Paths.get(a))无法正常工作。

解决方案

您可能需要查看提供了一个空字符串(它产生一个空的路径)和http://download.oracle.com/javase/7/docs/api/java/nio/file/Path.html有关空路径的详细信息:

你的代码得到一个空的路径是有效的,然后认为源和目的地是相同的。


I'm really wondering what this code does:

scala> import java.nio.file._
import java.nio.file._

scala> Files.copy(Paths.get(""), Paths.get(""))
res0: java.nio.file.Path = 

Shouldn't that throw a NoSuchFileException?

Reading the JavaDoc reveals:

But I'm not sure this is the true cause, because Files.copy(Paths.get("a"), Paths.get("a")) fails as expected.

解决方案

You might want to check http://download.oracle.com/javase/7/docs/api/java/nio/file/Paths.html for what paths.get does when provided an empty string (it generates an empty path) and http://download.oracle.com/javase/7/docs/api/java/nio/file/Path.html for details on what an empty path means:

So it looks like your code is getting an empty path which is valid and then considers the source and destination to be the same.

这篇关于当我复制两个空路径,为什么不抛出异常呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 17:04