Get file path and name

ReturnMethodSummary
FilegetAbsoluteFile()Returns the absolute form of this abstract pathname.
StringgetAbsolutePath()Returns the absolute pathname string of this abstract pathname.
FilegetCanonicalFile()Returns the canonical form of this abstract pathname.
StringgetCanonicalPath()Returns the canonical pathname string of this abstract pathname.
StringgetName()Returns the name of the file or directory denoted by this abstract pathname.
StringgetPath()Converts this abstract pathname into a pathname string.

import java.io.File;
import java.io.IOException;

public class Main {

  public static void main(String[] args) {
    File aFile = new File("a.htm");
    System.out.println(aFile.getAbsoluteFile());
    System.out.println(aFile.getAbsolutePath());
    try {
      System.out.println(aFile.getCanonicalFile());

      System.out.println(aFile.getCanonicalPath());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println(aFile.getName());
    System.out.println(aFile.getPath());


  }
}

The output:


C:\Java_Dev\eclipse31\test\a.htm
C:\Java_Dev\eclipse31\test\a.htm
C:\Java_Dev\eclipse31\test\a.htm
C:\Java_Dev\eclipse31\test\a.htm
a.htm
a.htm
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.