Repository : save testé
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user