Using the File. delete( ) function of the File class; we can delete a file in Java. The file or directory indicated by the abstract pathname is deleted by the delete( ) method. If the pathname is a directory, it must be empty to be deleted.