How do I delete a file?

Bookmark this example!  
Category: java.io, viewed: 1333 time(s).
 
package org.kodejava.sample.java.io;
 
import java.io.File;
 
public class FileDeleteExample
{
    public static void main(String[] args)
    {
        // When want to delete a file named readme.txt
        File file = new File("readme.txt");
 
        // Checks if the file is exists before deletion.
        if (file.exists())
        {
            System.out.println("Deleting file " + file.getAbsolutePath());
            // Use the delete method to delete the given file.
            file.delete();
        } else
        {
            System.out.println(file.getAbsolutePath() + " doesn't exists.");
        }
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium