Get name of parent directory
- /*
- Get name of parent directory
- This Java example shows how to get a name of the parent directory of a particular
- file or directory using getParent method of Java File class.
- */
- import java.io.*;
- public class GetParentDirectory {
- public static void main(String[] args) {
- //create file object
- File file = new File("C://FileIO/demo.txt");
- /*
- * To get parent directory of a particular file, use
- * String getParent() method of Java File class.
- */
- String strParentDirectory = file.getParent();
- System.out.println("Parent directory is : " + strParentDirectory);
- }
- }
- /*
- Output would be
- Parent directory is : C:\FileIO
- */



