0

我的 Java 程序使用Snake YAML来解析一个 YAML 文件,该文件包含要显示给用户的文本。其中一些字符串包含版权符号 (©)。当我在我的 IDE (IntelliJ IDEA) 中运行程序时,版权符号会正确呈现。但是,一旦我构建了一个工件并运行生成的 JAR 文件,版权符号就会改为呈现“©”(不带引号)。

如何更改我的程序以正确读取文件或更改 YAML 文件以便正确呈现版权符号?

这是加载 YAML 的 Java 代码。

private void loadOptions () 
        throws IOException, SAXException, ParserConfigurationException
{
  Yaml yaml = new Yaml();
  String filePath = "./config.yml";
  Reader reader = null;

try {
    reader = new FileReader(filePath);
    options = (Map<String, Map>) yaml.load(reader);
  }
  catch (FileNotFoundException e) {
    String msg = "Either the YAML file could not be found or could not be read: " + e;
    System.err.println(msg);
  }

  if (reader != null) {
    reader.close();
  }
}

以下是相关 YAML 代码的示例:

text:
  copyright:
    © 2007 Acme Publishing (info@example.org)
4

1 回答 1

1

感谢@Amadan 对我的问题的评论,我被引导将我的 Java 代码更改为以下内容,从而解决了问题:

private void loadOptions ()
    throws IOException, SAXException, ParserConfigurationException
{
  Yaml yaml = new Yaml();
  String filePath = "./config.yml";
  Reader reader = null;

  try {
    FileInputStream file = new FileInputStream(filePath);
    reader = new InputStreamReader(file, "UTF-8");
    options = (Map<String, Map>) yaml.load(reader);
  }
  catch (FileNotFoundException e) {
    String msg = "Either the YAML file could not be found or could not be read: " + e;
    System.err.println(msg);
  }

  if (reader != null) {
    reader.close();
  }
}
于 2014-05-27T06:47:13.057 回答