Skip to content

Commit

Permalink
1.23
Browse files Browse the repository at this point in the history
- create backup
  • Loading branch information
Osiris-Team committed Nov 7, 2023
1 parent e848057 commit 00fc198
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/osiris/jsqlgen/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -55,6 +57,9 @@ public static void save(){
file.getParentFile().mkdirs();
file.createNewFile();
}
// Before writing, backup the existing file
Files.copy(file.toPath(), new File(file.getPath()+"_backup.json").toPath(),
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
StringWriter sw = new StringWriter(); // Passing the filewriter directly results in a blank file
parser.toJson(instance, sw);
String out = sw.toString();
Expand Down

0 comments on commit 00fc198

Please sign in to comment.