1// java delete file
2import java.io.File;
3public class JavaDeleteFile
4{
5 public static void main(String[] args)
6 {
7 try
8 {
9 File file = new File("E:\\example.txt");
10 if(file.delete())
11 {
12 System.out.println(file.getName() + " file deleted.");
13 }
14 else
15 {
16 System.out.println("failed");
17 }
18 }
19 catch(Exception ex)
20 {
21 ex.printStackTrace();
22 }
23 }
24}