Skip to content

Commit

Permalink
Update DataStorage.java
Browse files Browse the repository at this point in the history
- Fix error in folder creation.
- Use output file directly instead of asserting a new one
  • Loading branch information
TreemanKing committed May 11, 2024
1 parent 2064c3f commit a350c8c
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public <T> T loadJson(Class<T> dataHolder, String location) {
public boolean storeJson(Object dataHolder, String location) {
// Create folders if they don't exist
File outFile = new File(this.dataFolder, location);
if (!outFile.exists()) {
if (!outFile.getParentFile().exists()) { // Check if parent folder exists
if(!outFile.getParentFile().mkdirs()) {
infoLogger.warning("Failed to create folder for file: " + location);
}
}
String json = gson.toJson(dataHolder);
try {
FileWriter fileWriter = new FileWriter(new File(this.dataFolder, location));
FileWriter fileWriter = new FileWriter(outFile); // Use outFile directly here
fileWriter.write(json);
fileWriter.close();
return true;
Expand Down

0 comments on commit a350c8c

Please sign in to comment.