How to find if a pathname is a directory in java?

Below java code shows how to find whether the specified path is directory or file –

/****************************************************************************************
 * Created on 03-2012 Copyright(c) http://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.javaio;

import java.io.File;

/**
 * Created by http://kodehelp.com
 * Date: 03/05/2012
 */
public class IsDirectoryDemo {


	public static void main(String[] args) {
		
		File file = new File("/home/kodehelp/");

        // 
        // To check whether the path is directory or file, you need to call 
        // isDirectory() method of the File class.
        //
        if (file.isDirectory()) {
            System.out.println("This file is a kodehelp directory.");
        } else {
            System.out.println("This is just a kodehelp file.");
        }

	}

}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.