Java IO Tutorial - Java File.getCanonicalFile()


File.getCanonicalFile() has the following syntax.

public File getCanonicalFile()   throws IOException


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

// ww  w.  j  ava2

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

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

    File path = f.getCanonicalFile();

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


The code above generates the following result.