How do I check for a directory?

Bookmark this example!  
Category: java.io, viewed: 1526 time(s).
 
package org.kodejava.sample.java.io;
 
import java.io.File;
 
public class IsDirectoryExample
{
    public static void main(String[] args)
    {
        // You want to check whether an instance of a file is
        // representating a directory or not.
        File file = new File("FooBar.txt");
 
        // To do this you can check it by calling isDirectory()
        // method in the File class.
        if (file.isDirectory())
        {
            System.out.println("This file is a directory.");
        } else
        {
            System.out.println("This is just an ordinary file.");
        }
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!
Firefox 2
Google

100 Top & Latest

GetJava Download Button

Locations of visitors to this page
eXTReMe Tracker
visitor stats