import java.io.*;
import java.util.*;
public class Delete{
private Scanner scan=new Scanner(System.in);
private String path;
public void input(){
try{
System.out.printf("File/Folder Path: ");
setPath(getScan().nextLine());
}
catch(InputMismatchException e){
System.err.println("Error Occured!\n"+e.getMessage());
System.exit(0);
}
}
public void compute(){
File deleted=new File(getPath());
if(deleted.exists()){
boolean done=deleted.delete();
if(done==true)
System.out.println("File/Folder Deleted!");
else
System.out.println("File/Folder was not Deleted!");
System.out.println("Path: "+deleted.getPath());
System.out.println("Parent Path: "+deleted.getParent());
}
else
System.err.println("Invalid Path!");
}
public static void main(String[] args){
Delete obj=new Delete();
obj.input();
obj.compute();
}
/**
* @return the scan
*/
public Scanner getScan() {
return scan;
}
/**
* @param scan the scan to set
*/
public void setScan(Scanner scan) {
this.scan = scan;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
}
import java.util.*;
public class Delete{
private Scanner scan=new Scanner(System.in);
private String path;
public void input(){
try{
System.out.printf("File/Folder Path: ");
setPath(getScan().nextLine());
}
catch(InputMismatchException e){
System.err.println("Error Occured!\n"+e.getMessage());
System.exit(0);
}
}
public void compute(){
File deleted=new File(getPath());
if(deleted.exists()){
boolean done=deleted.delete();
if(done==true)
System.out.println("File/Folder Deleted!");
else
System.out.println("File/Folder was not Deleted!");
System.out.println("Path: "+deleted.getPath());
System.out.println("Parent Path: "+deleted.getParent());
}
else
System.err.println("Invalid Path!");
}
public static void main(String[] args){
Delete obj=new Delete();
obj.input();
obj.compute();
}
/**
* @return the scan
*/
public Scanner getScan() {
return scan;
}
/**
* @param scan the scan to set
*/
public void setScan(Scanner scan) {
this.scan = scan;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
}
Comments