forked from sozalpasan1/milofilewritercode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFileWriter.java
More file actions
44 lines (39 loc) · 1.43 KB
/
MyFileWriter.java
File metadata and controls
44 lines (39 loc) · 1.43 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
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 file : files){
File f = new File(file);
if (f.exists()){
totalSize += f.length();
}
}
System.out.println ("Total Size of all files: ... TBD ... 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();
}
}
}