Java @ Desk: File I/O
Showing posts with label File I/O. Show all posts
Showing posts with label File I/O. Show all posts

Saturday, December 7, 2013

Java File Delete and DeleteOnExit

8:14 AM 0
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.

Java Create Single Directory and Multiple Directories

7:43 AM 0
Java Create Single Directory and Multiple Directories

To create a new directory 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) The directory to be created, exists or not. It can be checked using the exists() method
2) If the above condition return false, the method mkdir() is called in order to create single directory.
3) If the above condition return false, the method mkdirs() is called in order to create multiple directories.

Java Create New File

7:28 AM 0
Java Create New File

To create a new 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 file operation

While creating a file, following things need to be checked:
1) The file to be created, exists or not. It can be checked using the exists() method
2) If the above condition return false, the method createNewFile() is called.