|
Is Directory
The following example shows how to check whether the given file is a directory or file.
|
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
|
|