Delete File in Java

Deleting files in Java is really simple. You can just use delete method of File. Here is a sample code:

package file;
public class DeleteFile {
	public static void main(String[] args) {
		File file = new File("/home/programcreek/Desktop/s1");
		if (file.delete()) {
			System.out.println(file.getName() + " is deleted!");
		} else {
			System.out.println("File is not deleted.");
Category >> I/O  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";