Get relative path from one path - Java File Path IO

Java examples for File Path IO:Path

Description

Get relative path from one path

Demo Code


import java.nio.file.Path;
import java.nio.file.Paths;

public class NormalizeWeirdBehaviour {

    public static void main(String[] args) {
        Path p1 = Paths.get("/personal/./photos/../readme.txt");
        Path p2 = Paths.get("/personal/index.html");
        Path p3 = p1.relativize(p2);
        System.out.println(p3); // try to guess it before you run it...
    }/*w  ww  .  j  a v a2  s .co  m*/
}

Related Tutorials