Get file path and name
File getAbsoluteFile()
- Returns the absolute form of this abstract pathname.
String getAbsolutePath()
- Returns the absolute pathname string of this abstract pathname.
File getCanonicalFile()
- Returns the canonical form of this abstract pathname.
String getCanonicalPath()
- Returns the canonical pathname string of this abstract pathname.
String getName()
- Returns the name of the file or directory denoted by this abstract pathname.
String getPath()
- 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
Home
Java Book
File Stream
Java Book
File Stream
File:
- File
- Constants from File class
- Create file object
- Is it executable, readable or writable
- Compare two file path
- Create a file
- Delete a file
- Is it a file or a directory
- Whether the file or directory denoted by this abstract pathname exists
- Whether this abstract pathname is absolute
- Is this file hidden
- Get the file last modified time
- Get the file size
- Get file path and name
- Get free space, total space, usable space
- Get parent file
- Return file in a directory
- The file system roots
- Create new directories
- Rename file
- Change to executable, readable, writable
- Change last-modified time
- Get string representation of a file location
- Convert file location to URI and URL