-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d61bc7
commit 7fc1530
Showing
5 changed files
with
54 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package util; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
public class Persistence { | ||
private static final String saveFileName = "stlFiles.json"; | ||
|
||
private static void checkFileExists() throws IOException { | ||
var file = new File(saveFileName); | ||
if (!file.exists()) { | ||
file.createNewFile(); | ||
Files.writeString(file.toPath(), "{}"); | ||
} | ||
} | ||
|
||
public static JSONObject readStlSaveFile() throws IOException { | ||
checkFileExists(); | ||
var jsonString = Files.readString(new File(saveFileName).toPath()); | ||
return new JSONObject(jsonString); | ||
} | ||
|
||
public static void writeStlSaveFile(JSONObject jsonObject) throws IOException { | ||
checkFileExists(); | ||
Files.writeString(new File(saveFileName).toPath(), jsonObject.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters