Java IO Tutorial - Java File.getAbsolutePath()


File.getAbsolutePath() has the following syntax.

public String getAbsolutePath()


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

/* www .  ja v a  2s  . c  o  m*/

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.