tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > Delete File

Delete File 

The following example shows how to delete a given file.

File Name  :  
com/bethecoder/tutorials/io/DeleteFile.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

import java.io.File;

public class DeleteFile {

  /**
   @param args
   */
  public static void main(String[] args) {
    File file2Delete = new File("C:\\abc.txt");

    //true if and only if the file or directory is successfully deleted; false otherwise 
    System.out.println("File deleted successfully : " + file2Delete.delete());
  }

}
   

It gives the following output,
File deleted successfully : true



 
  


  
bl  br