3:09 pm - Saturday October 21, 0580

Program is used to tests the existence of the file or directory defined by this abstract pathname. Boolean Exist()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

The java.io.File.exists() method tests the existence of the file or directory defined by this abstract pathname.

EXAMPLE PROGRAM


import java.io.File;

public class BooleanExistMethod {
	public static void main(String[] args) {

		File f = null;
		Boolean bool = false;
		try {
			f = new File("template.txt");

			f.createNewFile();
			bool = f.exists();
			System.out.println("file exist: " + bool);
			if (bool == true) {
				// f.delete();
				System.out.println("delete() invoked");
			}
			bool = f.exists();
			System.out.println("file exist: " + bool);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}



Output  file exist: true

delete() invoked

file exist: true

 Explanation:

The java.io.File.exists() method tests the existence of the file or directory defined by this abstract pathname.

 Parameter: NA

 Return:  

The method returns boolean true, if and only if the file defined by the abstract pathname exists; else false

 Throw: NA

BACK

Filed in: Z-A All Java Codes

Comments are closed.