From 68218cbb49700cc366c489d55c821a1ec23bc83f Mon Sep 17 00:00:00 2001 From: PasserbyAlpha Date: Fri, 22 Apr 2022 23:11:29 +0800 Subject: [PATCH 1/2] fixed encoding problem when generating gm handbook --- src/main/java/emu/grasscutter/tools/Tools.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index 6f6466773..fd614f4c1 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -1,8 +1,11 @@ package emu.grasscutter.tools; +import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; +import java.io.InputStreamReader; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -30,7 +33,7 @@ public final class Tools { ResourceLoader.loadResources(); Map map; - try (FileReader fileReader = new FileReader(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json"))) { + try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json")), StandardCharsets.UTF_8)) { map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken>() {}.getType()); } From 6cc0fdaeedba5b684a6247fe0d8e3cfedff0c78c Mon Sep 17 00:00:00 2001 From: PasserbyAlpha Date: Sat, 23 Apr 2022 02:28:34 +0800 Subject: [PATCH 2/2] use OutputStreamWriter to ensure the charset of output is utf8 [from fumbling644o] --- src/main/java/emu/grasscutter/tools/Tools.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index fd614f4c1..1afcc1ebe 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -1,9 +1,11 @@ package emu.grasscutter.tools; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; @@ -39,7 +41,7 @@ public final class Tools { List list; String fileName = "./GM Handbook.txt"; - try (FileWriter fileWriter = new FileWriter(fileName); PrintWriter writer = new PrintWriter(fileWriter)) { + try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8), false)) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = LocalDateTime.now();