Java File getAbsolutePath() Method
Example
Get the full path of a file:
import java.io.File;
public class Main {
public static void main(String[] args) {
File myFile = new File("filename.txt");
System.out.println(myFile.getAbsolutePath());
}
}
Note: The output depends on the computer and its settings.
Definition and Usage
The getAbsolutePath() method returns the absolute path of the file. An absolute path is the full path, which starts at the top folder of the drive, like C:\Users\MyName\filename.txt.
If the File object has a short path, like filename.txt, Java adds the folder that the program runs in to the start. The file does not need to exist.
Note: The output depends on the computer, and on the folder that the program runs in.
Syntax
public String getAbsolutePath()
Parameter Values
None.
Technical Details
| Returns: | The absolute path, as a String. |
|---|
Related Pages
❮ File Methods