2:14 am - Wednesday April 26, 2017

Program is used to deletes the file or directory defined by the abstract path name using Void deleteOnExit()

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.deleteOnExit() method deletes the file or directory defined by the abstract path name when the virtual machine terminates. Files or directories are deleted in the reverse order as they are registered.

EXAMPLE PROGRAM


import java.io.File;

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

		File f = null;
		try {
			f = File.createTempFile("tem", ".txt");
			System.out.println("file path:" + f.getAbsolutePath());
			f.deleteOnExit();

			f = File.createTempFile("temp", null);
			System.out.println("file path:" + f.getAbsolutePath());
			f.deleteOnExit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Output:

file path:C:\Users\Sathiya\AppData\Local\Temp\tem3435866396425988007.txt

file path:C:\Users\Sathiya\AppData\Local\Temp\temp5574139238177604374.tmp

Explanation:

The java.io.File.deleteOnExit() method deletes the file or directory defined by the abstract path name when the virtual machine terminates. Files or directories are deleted in the reverse order as they are registered.

Parameter: NA

Return:      The method does not return any value.

Throws:

SecurityException — If SecurityManager.checkWrite(java.lang.String) method denies delete access to the file

Filed in: Z-A All Java Codes

Comments are closed.