Delete File

import java.util.Scanner;

class deletefile {
	public static void main(String args[]) throws IOException {
		Scanner filename = new Scanner(;
		System.out.println("Enter the file name to delete:");

		/* Deleting file */
		boolean success = (new File(filename.nextLine())).delete();
		if (success) 
			System.out.println("File has been deleted successfully!"); 
			System.out.println("File not found or not able to deleted!");

File has been deleted successfully!


File not found or not able to deleted!

Learn more about Delete File

Recommended for you