Deleting a file in java, It is pretty easy, Here is the sample code, Just copy and paste on our Java IDE and test this below program, It deletes a file from given directory.

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

public class CodeTest{

public static void main(String[] args) throws Exception{
Files.delete(Paths.get(new URI(“file:///doc.txt”)));