-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWriter.java
More file actions
41 lines (36 loc) · 979 Bytes
/
FileWriter.java
File metadata and controls
41 lines (36 loc) · 979 Bytes
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
package cs3500.pa05.model;
import cs3500.pa05.model.json.WeekJson;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* Writes the current data inputted into the week GUI to a .bujo file
*/
public class FileWriter {
private WeekJson weekJson;
private Path path;
private BufferedWriter writer;
/**
* Instantiates a FileWriter.
*
* @param week the week to write
* @param path the path to write to
*/
public FileWriter(WeekJson week, String path) {
this.weekJson = week;
this.path = Path.of(path);
}
/**
* Writes this WeekJson to the file path.
*/
public void writeBujo() {
try {
writer = Files.newBufferedWriter(this.path);
writer.write(JsonUtils.serializeRecord(this.weekJson).toPrettyString());
writer.flush();
} catch (IOException e) {
System.err.println("Path not found");
}
}
}