Create new file on export if not exists

- Added folder creation to SpecificExport#exportPlayersTableJSON
  in case the folder doesn't exist
- Added StandardOpenOption.CREATE to file write, so that the file
  will be created if it doesn't exist

Affects issues: #1066
This commit is contained in:
Rsl1122 2019-06-22 09:11:45 +03:00
parent 654a018d3d
commit e5a336a249

View File

@ -29,6 +29,7 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -75,7 +76,7 @@ public abstract class SpecificExport {
protected abstract String getPath();
protected void export(File to, List<String> lines) throws IOException {
Files.write(to.toPath(), lines, StandardCharsets.UTF_8);
Files.write(to.toPath(), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE);
}
File getServerFolder() {
@ -147,6 +148,7 @@ public abstract class SpecificExport {
}
private void exportPlayersTableJSON(File htmlLocation, UUID serverUUID) throws IOException {
htmlLocation.mkdirs();
File exportFile = new File(htmlLocation, "players_table.json");
export(exportFile, Collections.singletonList(jsonFactory.serverPlayersTableJSON(serverUUID)));
}