-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWork.java
More file actions
35 lines (24 loc) · 760 Bytes
/
Copy pathFileWork.java
File metadata and controls
35 lines (24 loc) · 760 Bytes
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
import java.awt.*;
import java.io.File;
class FileWork { // This class is responsible for handling individual files
private File file;
FileWork (File file) {
System.out.println("\nThe element is a file.");
this.file = file;
}
boolean deleteFile() { // Deletion of a file
try {
return file.delete();
} catch (Exception e) {
System.out.println("Something went wrong with deleting file " + file.getName());
return false;
}
}
void openFile() { // Opens file using default OS dialogue
try {
Desktop.getDesktop().open(file);
} catch (Exception e) {
System.out.println("Failed to open the file.");
}
}
}