import java.io.*;
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
String fname, str;
Scanner scan = new Scanner(System.in);
// enter file name with extension to delete
System.out.print("Enter File Name to Delete : ");
fname = scan.nextLine();
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(fname));
out.write("aString1\n");
out.close();
boolean success = (new File(fname)).delete();
if(success)
{
System.out.println("The File '" + fname + "' has been Deleted Successfully..!!");
}
}
catch(IOException e)
{
System.out.println("Exception Occurred : " + e);
System.out.println("File does not exist or deleted..!!");
}
}
}
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.