Java 删除文件2


Java 删除文件2

import java.io.File;

public class DeleteFileExample {
   public static void main(String[] args) {
      try {
         File file = new File("C:\\Users\\codingdict7\\Desktop\\abc.txt");
         if(file.delete()) {
            System.out.println(file.getName() + " is deleted!");
         } else {
            System.out.println("Delete operation is failed.");
         }
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}