How do I check if a file exists in Java and then delete that file

Updated:13/feb/2020 by Computer Hope

import java.io.*;
import java.util.*;
class FileExample2
{
	public static void main(String args[]) 
{
    File myfile=new File("D:/Assignments/message.txt");
    System.out.println(myfile.exists());
    myfile.delete();
    System.out.println(myfile.exists());
}
}