1. Introduction
The getAbsolutePath() method returns the absolute path of the given file or directory. The method is system-dependent. On Windows OS a relative path is made absolute by resolving ti against the current folder of the drive named by the pathname. On UNIX a relative path is made absolute by resolving the current user directory.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- String - the absolute pathname of the given file or directory
Throws
- SecurityException - if a required system property value cannot be accessed.
3. Examples
3.1. Program that prints several absolute paths using getAbsolutePath()
method
When the .java
file was runned under /home/frontbackend/projects/tutorials
directory we will have the following output:
4. Conclusion
In this article, we showcased the File.getAbsolutePath()
method that returns the absolute path of the specified file or directory. Keep in mind that this method works differently on Windows and Unix OS.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}