This program will delete an existing file. There is a method delete() of File class which is used to delete the file and returns true or false, if the file deletes method returns true otherwise false.
In this program. Firstly we are checking file exists or not using the File.exists() method, if the file exits program will move to the file delete code and the file will be deleted using File.delete().
Delete File using Java Program
Output: