Java Programming

Delete File

Java Programming example for delete file from current directory

10/14/2021
0 views
delete-file.javaJava
import java.io.*;
import java.util.Scanner;

class deletefile {
	public static void main(String args[]) throws IOException {
		Scanner filename = new Scanner(System.in);
		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!"); 
		else
			System.out.println("File not found or not able to deleted!");
	}
}




/* Output */
File has been deleted successfully!

/* ---------------------- */

File not found or not able to deleted!
Java tutorialDelete FileRemove File

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com