tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > Is Directory

Is Directory 

The following example shows how to check whether the given file is a directory or file.

File Name  :  
com/bethecoder/tutorials/io/DirectoryTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

import java.io.File;

public class DirectoryTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    File file = new File("C:\\file_ops.txt");
    
    if (file.isDirectory()) {
      System.out.println(file + " is a directory");
    else {
      System.out.println(file + " is a file");
    }
    
    file = new File("C:\\Temp");
    
    if (file.isDirectory()) {
      System.out.println(file + " is a directory");
    else {
      System.out.println(file + " is a file");
    }
    
  }

}
   

It gives the following output,
C:\file_ops.txt is a file
C:\Temp is a directory



 
  


  
bl  br