http://www.mkyong.com/java/how-to-delete-file-in-java/
No nonsense, just issue the File.delete() to delete a file, it will return a boolean value to indicate the delete operation status; true if the file is deleted; false if failed.
Example
In this example, it will delete a log file named “c:\\logfile20100131.log”.
package com.mkyong.file;
import java.io.File;
public class DeleteFileExample
{
public static void main(String[] args)
{
try{
File file = new File("c:\\logfile20100131.log");
if(file.delete()){
System.out.println(file.getName() + " is deleted!");
}else{
System.out.println("Delete operation is failed.");
}
}catch(Exception e){
e.printStackTrace();
}
}
}
'Programming' 카테고리의 다른 글
(JavaScript) How to load local script files as fallback in cases where CDN are blocked/unavailable? (0) | 2013.08.30 |
---|---|
HTML Textbox Input Tooltip? (0) | 2013.08.29 |
C# Language Specification Version 5.0 (0) | 2013.08.25 |
racket-clojure (0) | 2013.08.21 |
The Anti-Human Consequences of Static Typing (0) | 2013.08.20 |