-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyFileWriter.java
More file actions
48 lines (40 loc) · 1.57 KB
/
MyFileWriter.java
File metadata and controls
48 lines (40 loc) · 1.57 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
import java.io.*;
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
public class MyFileWriter {
private static void printFileSize (String filePath){
File file = new File(filePath);
System.out.println(file.length());
}
public static void printTotalFileSize (String... files){
long totalSize = 0;
for(String fileName : files){
File file = new File(fileName);
if(file.exists()){
totalSize += file.length();
}
}
System.out.println ("Total Size of all files: " + totalSize + " Bytes");
}
public static void main(String[] args) {
//printFileSize("MyFileWriter.java");
String secretPassword = "secretpassword";
String secretData = "sean ozalpasan (idk what else to put here)";
//Create a secretpassword txt file in the root directory
try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(".hiddenkey.txt"))){
outputStream.write(secretPassword.getBytes());
outputStream.close();
}
catch (IOException e){
e.printStackTrace();
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File("/home/milomessinger/exampledir/.secret/secret.dat")))){
writer.write (secretData);
writer.close();
}
catch (IOException e){
e.printStackTrace();
}
printTotalFileSize(".hiddenkey.txt", ".gitignore", "/home/milomessinger/exampledir/.secret/secret.dat");
}
}