Java Files delete file

Description

Java Files delete file

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args){
    Path p = Paths.get("C:/Main.java");

    try {/* w  w  w . j a  v  a  2 s .  c om*/
      // Delete the file
      Files.delete(p);
      System.out.println(p + " deleted successfully.");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}



PreviousNext

Related