Java IO Tutorial - Java File.getAbsolutePath()








Syntax

File.getAbsolutePath() has the following syntax.

public String getAbsolutePath()

Example

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

/* www .  ja v a  2s  . c  o  m*/
import java.io.File;

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

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

    String path = f.getAbsolutePath();

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

  }
}

The code above generates the following result.