简体   繁体   中英

Java - create relative java.nio.Path from two java.nio.Path's

I have a java.nio.Path which points to an absolute path:

/home/user/project/resources/configuration.xml

I have a second java.nio.Path which points to the root directory of the project, also an absolute path:

/home/user/project

Is it now possible to create a java.nio.Path which holds the relative path between the two:

resources/configuration.xml

This is precisely what the relativize(Path) method does:

Path confFile = Paths.get("/home/user/project/resources/configuration.xml");
Path rootDir  = Paths.get("/home/user/project");
Path relative = rootDir.relativize(confFile);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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