How do I check for a directory?
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!
Related Examples
- How do I store properties as XML file?
- How do I load properties from XML file?
- How do I convert InputStream to String?
- How do I convert string into InputStream?
- How do I get an exception stack trace message?
- How do I use Console class to read user input?
- How do I store objects in file?
- How do I use DataInputStream and DataOutputStream?
- How do I use RandomAccessFile class?
- How do I create a directories recursively?