How to delete a file in Java

1 Answer

0 votes
package javaapplication1;
 
import java.io.*;
 
public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            File file = new File("d:\\data.bin");
        	
    	    if (file.delete())
    		    System.out.println(file.getName() + " deleted");
    	    else
    		    System.out.println("Delete error");
        }
        catch (Exception e) 
        {
            System.out.println("Error deleting file: " + e.getMessage());   
        }
    }
}
 
/*
 
run:
 
data.bin deleted
 
*/

 



answered Aug 14, 2015 by avibootz

Related questions

1 answer 166 views
1 answer 187 views
1 answer 105 views
1 answer 132 views
1 answer 180 views
...