Java IO Tutorial - Java File.getCanonicalPath()


File.getCanonicalPath() has the following syntax.

public String getCanonicalPath()   throws IOException


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

//  w ww  .j  av  a2  s. c o m


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.