Repository : save testé

This commit is contained in:
Maximilien LEDOUX
2022-03-08 11:45:18 +01:00
parent ac04f86e72
commit d979fbd1f3
3 changed files with 61 additions and 5 deletions

View File

@@ -12,10 +12,10 @@ public class Repository {
//static final String CONFIG_FILE_PATH = "../../resources/config.json";
void save(String filePath, Adapter adapter) {
static void save(String filePath, Adapter adapter) {
if (filePath != null) {
String jsonAppData = adapter.toString();
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
bufferedWriter.write(jsonAppData);
bufferedWriter.flush();
} catch (IOException e) {
@@ -29,9 +29,9 @@ public class Repository {
return adapter.fromString(jsonString);
}
private String readFile(String filePath) {
static private String readFile(String filePath) {
StringBuilder builder = new StringBuilder();
try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath), StandardCharsets.UTF_8)) {
try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8)) {
while (reader.ready()) {
builder.append(reader.readLine());
}