Java I/O – Get parent directory of the file or directory




getParent() and getParentFile() Methods

In Java File class a member method getParent() returns the path name string of the parent directory named by this abstract path name, or null if this pathname does not name a parent.
getParentFile(): Returns the parent directory as a File object, or null if this File object does not have a parent.
Lets take an example to understand the method in a better way. In this example we will construct the file path using File constructor.

 

OUTPUT :
C:\jdk
C:\jdk
C:\jdk\FileName.java

Reference:
https://docs.oracle.com/javase/7/docs/api/java/io/File.html


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com