Java Path get real path by following symbolic link

Description

Java Path get real path by following symbolic link

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

public class Main {
  public static void main(String[] args) {
    try {/*from   w  ww .  j a va  2s.  c om*/
      Path p = Paths.get("Main.txt");

      // Follow link for p if it is a symbolic link
      Path realPath = p.toRealPath();

      System.out.println("RealPath:" + realPath);
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
}



PreviousNext

Related