forked from avivpilipski/fileWriter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFileWriter.java
More file actions
30 lines (23 loc) · 1.03 KB
/
MyFileWriter.java
File metadata and controls
30 lines (23 loc) · 1.03 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
import java.io.*;
public class MyFileWriter {
public static void printFileSize (String fileName) {
File file = new File (fileName);
System.out.println(file.length());
}
public static void main(String[] args) throws IOException {
String password = "Sorry I Couldn't Find Your Bank Account Info, I Tried Mr. Theiss :()";
String topSecretData = "I have neither given nor recieved unauthorized aid on this project. My name affirms my honor";
// 2. Using BufferedWriter
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(".notTheissBankAccount.txt"))) {
bufferedWriter.write(password);
} catch (IOException e) {
e.printStackTrace();
}
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(".notClassified/honorCode.hw"))) {
bufferedWriter.write(topSecretData);
} catch (IOException e) {
e.printStackTrace();
}
printFileSize(".notTheissBankAccount.txt");
}
}