-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyFileWriter.java
More file actions
52 lines (42 loc) · 1.68 KB
/
MyFileWriter.java
File metadata and controls
52 lines (42 loc) · 1.68 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
import java.io.*;
public class MyFileWriter {
public static void createHiddenFile() {
try {
File hiddenFile = new File("aboutSydney.txt");
if (!hiddenFile.exists()) {
BufferedWriter writer = new BufferedWriter(new FileWriter(hiddenFile));
writer.write("Haha Nathan I don't care about your fun facts");
writer.close();
System.out.println("Hidden file created with password.");
}
else {
System.out.println("The hidden file already exists.");
}
} catch (IOException e) {
System.out.println("Error creating the hidden file.");
e.printStackTrace();
}
}
public static void createRegularFileInHiddenFolder() {
try {
File folder = new File(".classified");
if (!folder.exists()) {
folder.mkdir();
System.out.println("Hidden folder created.");
}
File regularFile = new File(".classified", "confidential.dat");
BufferedWriter writer = new BufferedWriter(new FileWriter(regularFile));
writer.write("This is confidential information.");
writer.close();
System.out.println("Regular file created inside the hidden folder.");
} catch (IOException e) {
System.out.println("Error creating the regular file inside the hidden folder.");
e.printStackTrace();
}
System.out.println("Sydney's herrrre");
}
public static void main(String[] args) {
createHiddenFile();
createRegularFileInHiddenFolder();
}
}