Java IO Tutorial - Java Path.toRealPath(LinkOption ... options)








Syntax

Path.toRealPath(LinkOption ... options) has the following syntax.

Path toRealPath(LinkOption ... options)  throws IOException

Example

In the following code shows how to use Path.toRealPath(LinkOption ... options) method.

//from w w w .  ja  va2s .com
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) {

    Path path = Paths.get("/tutorial/Java/JavaFX", "Topic.txt");

    // convert path to "real" path
    try {
      Path real_path = path.toRealPath(LinkOption.NOFOLLOW_LINKS);
      System.out.println("Path to real path: " + real_path);
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}