Get the relative path between two paths : Paths « JDK 7 « Java
- Java
- JDK 7
- Paths
Get the relative path between two paths
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args) {
Path firstPath = Paths.get("music/A.mp3");
Path secondPath = Paths.get("docs");
System.out.println("From firstPath to secondPath: "
+ firstPath.relativize(secondPath));
System.out.println("From secondPath to firstPath: "
+ secondPath.relativize(firstPath));
System.out.println();
}
}
Related examples in the same category