-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandler.java
More file actions
20 lines (19 loc) · 817 Bytes
/
FileHandler.java
File metadata and controls
20 lines (19 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.io.FileWriter;
import java.io.IOException;
public class FileHandler {
/**
* Saves the given ReadingMaterial object to the specified file.
* The material's string representation (from toString()) is appended to the file.
*
* @param material The ReadingMaterial object to save.
* @param filename The name of the file where the material will be saved.
*/
public static void saveToFile(ReadingMaterial material, String filename) {
try (FileWriter writer = new FileWriter(filename, true)) {
writer.write(material.toString() + "\n"); // Append the material's string representation to the file
} catch (IOException e) {
System.out.println("An error occurred while saving to file.");
e.printStackTrace();
}
}
}