Java Path get relative path

Description

Java Path get relative path

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

public class Main {
  public static void main(String[] args) {
    Path p1 = Paths.get("a");
    Path p2 = Paths.get("a", "b", "Data");
    System.out.println(p1.relativize(p2));
    System.out.println(p2.relativize(p1));

  }//from   w  w w .j a  va2s. com
}

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

public class Main {
  public static void main(String[] args) {
    Path p1 = Paths.get("a");
    Path p2 = Paths.get("b");
    System.out.println(p1.relativize(p2));
    System.out.println(p2.relativize(p1));

  }/*  www . j  a  va 2  s . co m*/
}



PreviousNext

Related