import java.io.*;

public class DeleteOperation {

  public static void main(String[] str) {

    if (str.length != 1) {    
      System.err.println("Deleting file or directory");
      System.exit(0);
    }
    
    try { 
		delete(str[0]); 
		}
		catch (IllegalArgumentException e) {
			System.err.println(e.getMessage()); 
			}
  }

  public static void delete(String filename) {

    File file = new File(filename);

    if (!file.exists()) fail("No such file or directory exist: " + filename);
    if (!file.canWrite()) fail("Can not delete as it is write protected: " + filename);

    if (file.isDirectory()) {
      String[] files = file.list();
      if (files.length > 0) fail("Can not delete as directory is not empty: " + filename);
    }
    boolean success = file.delete();    
    if (!success) fail("Delete: deletion failed");
  }
  protected static void fail(String msg) throws IllegalArgumentException {
    throw new IllegalArgumentException(msg);
  }
}
