Java File Delete and DeleteOnExit
To delete a file in java, following package is getting used
1) import java.io.File - To handle file operations
2) import java.io.IOException - To handle any exceptions occur during the directory operation
While creating a directory, following things need to be checked:
1) Check if the file exists using the exists() method. Not mandarory
2) Make a call to delete() method
There are two ways to delete a file in java
1) delete() - Returns true if the file gets deleted successfully. It deletes the file immediately as soon as the delete() method gets called
2) deleteOnExit() - The java.io.File.deleteOnExit() method deletes the file or directory defined by the abstract path name when the virtual machine terminates. It's purpose is to delete the file when the JVM exits.
To delete a file in java, following package is getting used
1) import java.io.File - To handle file operations
2) import java.io.IOException - To handle any exceptions occur during the directory operation
While creating a directory, following things need to be checked:
1) Check if the file exists using the exists() method. Not mandarory
2) Make a call to delete() method
There are two ways to delete a file in java
1) delete() - Returns true if the file gets deleted successfully. It deletes the file immediately as soon as the delete() method gets called
2) deleteOnExit() - The java.io.File.deleteOnExit() method deletes the file or directory defined by the abstract path name when the virtual machine terminates. It's purpose is to delete the file when the JVM exits.