The getParent() method returns the name of the parent directory for specified
File. If the path does not have any parent this method will return null. The method is very similar to getParentFile() but in this case we will get only the string representation of the parent folder, not the whole
2. Method signature
- method does not take any parameter
- String - the name of the parent directory or null if specified pathname does not have a parent
3.1. The program that prints the parent of specified
In this short article, we presented
File.getParent() with a simple example of how to use this method. We can use this method to retrieve the parent name of the directory up to the root folder.