Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a child NIO.2 Path from a parent Path instance

Tags:

java

path

nio

How do I create a java.nio.file.Path instance denoting a child path, if I already have an instance pointing to the parent directory on the same file system?

Currently, I'm using

final Path parent = Paths.get("usr", "local");
final Path child = Paths.get(parent.toString(), "bin");

-- but this doesn't look very elegant.

What I'm looking is some sort of a java.io.File(File parent, String child) constructor for NIO.2.

like image 592
Bass Avatar asked Feb 13 '17 15:02

Bass


1 Answers

You can write child = parent.resolve("bin");

resolve can take Path or String as argument.

like image 125
cshu Avatar answered Oct 20 '22 10:10

cshu