In this section, you will learn how to get the parent directory of the current working directory.
Program uses getParent() method of the File class object to find the parent directory name of the current directory.
getParent():
Above code returns the parent directory of the file/directory.
System.getProperty("user.dir"):
This method returns the user's current directory. The getProperty()
method
is the system method which is imported from the System class of the java.lang.*;
package. This method tells about the system property according to the indicating
argument. Here, the indicating argument user.dir indicates about the current
directory.
Here is the code of the program :
import java.io.*;
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Getting the Parents of file name path in Java View All Comments
Post your Comment