Java Path get real path by not following symbolic link

Description

Java Path get real path by not following symbolic link

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

public class Main {
  public static void main(String[] args) {
    try {/* www. j  a v a  2s.c o m*/
      Path p = Paths.get("test3.txt");

      // Do not follow link for p, if it is a symbolic link
      Path realPath = p.toRealPath(LinkOption.NOFOLLOW_LINKS);

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



PreviousNext

Related