Deleting a file

The source code for deleting a file is shown below.Here I am trying to delete the file if it is not a directory.


* User: Bijoy
* Date: 6/25/12
* Time: 9:18 PM
public class FileDelete {
public static void main(String[] args) {
try {
File file = new File("E:/temp/test.txt");
if (!file.isDirectory()) {
} else {
System.out.println("It is a directory");
} catch (Exception e) {

Remember, the specified file should be existing. If it is not existing please create the file in the correct path.

One thought on “Deleting a file

  1. Noble Attanasio says:

    Greetings people ! Nice page you have here!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">