How to get parent directory name

package JavaIOExample;

import java.util.Scanner;

 * Here we will learn to check parent directory name.
public class CheckParentDirectoryName {

	public static void main(String args[]) {
		Scanner scanner = new Scanner(;
		System.out.println("Enter the file path");
		String filePath =;
		File fileToTest = new File(filePath);

		if (!fileToTest.isDirectory()) {
			System.out.println("This is File");
			System.out.println("Parent Folder of this file is :"
					+ fileToTest.getParent());
		} else {
			System.out.println("This is Directory");
			System.out.println("Parent Folder of this directory is :"
					+ fileToTest.getParent());


By | 2012-09-21T19:43:42+00:00 September 21st, 2012|Code Base|0 Comments

About the Author:

Leave A Comment