file exists Example
file class exists example. This example shows you how to use exists method.
File class exists example. method generates boolean results after testing the existence of file or directory denoted by the abstract pathname.path is abstract as it is defined inside the system.method is called by the File class object.
Here is the code:-
/**
* @Program uses exists method to check the existence
* of files and directories in the passed abstract path.
* and generates boolean values true & false.
* Exists.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class Exists {
public static void main(String args[]) {
File coding = new File("/tmp/baadshah22653.tmp");
if (coding.exists() == true)
System.out.println("'.tmp' File Found : " + coding.exists());
else
System.out.println("'baadshah22653.tmp' File not Found : "
+ coding.exists());
File diary = new File("/home/mahendra/Desktop/baadshah");
if (diary.exists() == true)
System.out.println("directory baadshah found : " + diary.exists());
}
} |
Output of the program:-
'baadshah22653.tmp' File not Found : false
directory baadshah found : true |
|