Java File.getCanonicalPath()

Syntax

File.getCanonicalPath() has the following syntax.

public String getCanonicalPath()   throws IOException

Example

In the following code shows how to use File.getCanonicalPath() method.


/*from   w w  w  .j a  v a 2 s  . c  o  m*/

import java.io.File;

public class Main {
  public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("test.txt");

    String path = f.getCanonicalPath();

    System.out.print("Absolute Pathname " + path);

  }
}

The code above generates the following result.