-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDUDE3.java
More file actions
132 lines (105 loc) · 3.26 KB
/
DUDE3.java
File metadata and controls
132 lines (105 loc) · 3.26 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package GdP2;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DUDE3 {
public String BeginningPath;
public DUDE3(String BeginnigPath) {
this.BeginningPath = BeginnigPath;
}
public void setBeginningPath(String input) {
this.BeginningPath=input;
}
public void createPath() {
String path = "";
try {
System.out.print("Enter file name (enter /name to create a new direction) : ");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
path = this.BeginningPath+input.readLine().toString();
System.out.println();
System.out.println(path);
System.out.println();
}
catch(Exception e) {
System.out.print("Undetected failure "+e);
}
File file = new File(path);
boolean created = file.mkdir();
boolean existAlready = file.exists();
if(created) {
System.out.println("File created succesfully");
System.out.println();
System.out.println();
this.BeginningPath=path;
}
else if(!created && existAlready) {
System.out.println("File exist Already! \nPlease try an other path.");
}
else {
System.out.println("Pleas only use letters and numbers and use '/' to create a new path!");
}
}
public void copyFileTo() {
String pathTarget = "";
try {
System.out.print("Enter the target path, where you want to copy the file : ");
BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in));
pathTarget = input2.readLine().toString();
BufferedReader br = new BufferedReader(new FileReader(this.BeginningPath));
BufferedWriter bw = new BufferedWriter(new FileWriter(pathTarget));
String writing;
while((writing = br.readLine()) != null) {
bw.write(writing + "\n");
}
br.close();
bw.close();
}
catch(Exception e) {
System.out.print("Undetected failure "+e);
}
}
public void printOutFileDetails() {
File file = new File(this.BeginningPath);
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
System.out.println(pfad);
System.out.println();
if(file.exists()) {
System.out.println("File does exist");
System.out.println();
}
else {
System.out.println("File does not exist");
System.out.println();
}
long lastModifiedDay = file.lastModified();
System.out.println("Last modified day : "+sdf.format(lastModifiedDay));
System.out.println();
long fileSize = file.length();
System.out.println("File size : "+ fileSize+" Bytes");
System.out.println();
if(file.canExecute()) {
System.out.println("File executing: granted");
System.out.println();
}
else {
System.out.println("File executing: denied");
System.out.println();
}
if(file.canRead()) {
System.out.println("Reading: granted");
System.out.println();
}
else {
System.out.println("Reading: denied");
System.out.println();
}
if(file.canWrite()) {
System.out.println("Writing: granted");
System.out.println();
}
else {
System.out.println("Writing: denied");
System.out.println();
}
}
}