1. Introduction
The getParentFile() method returns the File
representation of parent directory if given file have a parent. The method returns null for the root directories in Unix OS /
, in Windows \\
.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- File - the
File
instance of the parent directory, or null if givenFile
does not have a parent
3. Examples
3.1. Program that prints parent directories using getParentFile()
method:
The output:
4. Conclusion
In this article, we presented File.getParentFile()
method that returns the parent directory of given File
instance. The method should be useful for most common operations on the filesystem in Java.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}