-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasic_FileDeleter.java
44 lines (33 loc) · 1.21 KB
/
Basic_FileDeleter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//2019 Java Learning Repo
//Basic File Deleter V1
//written by rwx777
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.util.Scanner;
public class Basic_FileDeleter {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Please enter File Path: ");
try {
final long startTime = System.currentTimeMillis();
Files.deleteIfExists(Paths.get(reader.nextLine()));
final long endTime = System.currentTimeMillis();
System.out.println("Deletion successful.");
long timetook = ((endTime - startTime) / 1000);
System.out.println("Total time: " + timetook + "s"); //prints out time it took
} catch (NoSuchFileException e) {
System.out.println("No such file or Directory.");
System.out.println("Deletion not successful.");
} catch (DirectoryNotEmptyException e) {
System.out.println("Directory is not empty.");
System.out.println("Deletion not successful.");
} catch (IOException e) {
System.out.println("Invalid permissions.");
System.out.println("Deletion not successful.");
}
reader.close();
}
}