file isDirectory Example
file class isDirectory example. This example shows you how to use isDirectory method.
File class isDirectory example. method generates boolean results after testing the specified abstract pathname is a directory or not.path is abstract as it is defined inside the System.method is being called through boolean variable.method returns true if and only if abstract pathname exists and is a directory.
Here is the code:-
/**
* @Program uses isDirectory method to check the abstract
* pathname passed is a Directory.
* IsDirectory.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.File;
public class IsDirectory {
public static void main(String args[]) {
File guilty = new File("/tmp/gconfd-mahendra");
File guilty1 = new File("baadshah.txt");
boolean fido = guilty.isDirectory(), fido1 = guilty1.isDirectory();
System.out.println("'IsDirectory' test results");
if (fido == true)
System.out.println("Directory found: " + fido);
else
System.out.println("Directory test result failed: " + fido);
if (fido1 == true)
System.out.println("Directory found: " + fido1);
else
System.out.println("Directory test result failed: " + fido1);
}
} |
Output of the program:-
'IsDirectory' test results
Directory found: true
Directory test result failed: false |
|