Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问Java 7 Java.nio.file.Path中的子文件/文件夹?_Java_Path_Nio_Java 7 - Fatal编程技术网

如何访问Java 7 Java.nio.file.Path中的子文件/文件夹?

如何访问Java 7 Java.nio.file.Path中的子文件/文件夹?,java,path,nio,java-7,Java,Path,Nio,Java 7,Java 7是作为for Java.io.File引入的 对于文件,当我访问特定目录下的文件时,我会执行以下操作: File parent = new File("c:\\tmp"); File child = new File(parent, "child"); // this accesses c:\tmp\child 用Path怎么做 我想这会有用的: Path parent = Paths.get("c:\\tmp"); Path child = Paths.get(parent.to

Java 7是作为for Java.io.File引入的

对于文件,当我访问特定目录下的文件时,我会执行以下操作:

File parent = new File("c:\\tmp");
File child = new File(parent, "child"); // this accesses c:\tmp\child
用Path怎么做

我想这会有用的:

Path parent = Paths.get("c:\\tmp");
Path child = Paths.get(parent.toString(), "child");
但是调用
parent.toString()
看起来很难看。有更好的方法吗?

在上使用该方法。

有两个使用此名称的方法。采用相对
路径
字符串
。它使用
路径
,在该路径上调用它作为父级,并适当地附加
字符串
或相对
路径

Path parent = Paths.get("c:\\tmp");
Path child = parent.resolve("child");