Tutorials Point


  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java Examples - Parent Directory


previous next AddThis Social Bookmark Button


Problem Description:

How to get the parent directory of a file?

Solution:

Following example shows how to get the parent directory of a file by the use of file.getParent() method of File class.

import java.io.File;

public class Main {
   public static void main(String[] args) {
      File file = new File("C:/File/demo.txt");
      String strParentDirectory = file.getParent();
      System.out.println("Parent directory is : " 
      + strParentDirectory);
   }
}

Result:

The above code sample will produce the following result.

Parent directory is : File


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names