Deleting A File
This program creates a File and if it does not exists already,and then deletes the file using the methods of the File class.
/*
http://www.ProbCOMP.com
This program creates a File and if it does not exists already,
And then deletes the file using the methods of the File class.
*/
import java.io.File;
import java.io.IOException;
public class DeleteFile {
public static void main(String[] args){
File file = new File(args[0]);
boolean create = false;
boolean delete = false;
try
{
create = file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if (create)
{
System.out.println("File created");
}
else
{
System.out.println("File already exists");
}
delete = file.delete();
if(delete)
{
System.out.println("File deleted");
}
else
{
System.out.println("File was not deleted");
}
}
}
Download Program


