楠木i
本帖最后由 1957863988 于 2019-3-10 15:33 编辑

a2 = new File (getDataFolder(), "a2.yml");
                if (!a2.exists()){
                        saveResource("a2.yml", true);
                }
a1(YamlConfiguration.loadConfiguration(a2));

然后我用

a2.set("测试","测试"); 设置
this.a1.save(this.a2); 保存
之后a2.yml里面的内容会变 Unicode 码

请问怎么解决。。

3TUSK
  1. //强制指定 UTF-8 编码方式即可
  2. YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(a2), StandardCharsets.UTF_8));
复制代码

楠木i

好像一样会变成Unicode编码。。

xiaodong150
你这个我不知道为啥 ,但是建议使用io

海螺螺
你的a1 a2都是些啥

假设这样
YamlConfiguration c = loadFromXxxx(...)
因为1.7 1.8老版本的YamlConfiguration类里有一条yanlOptions.setAllowUnicode(true),因此我们要手动改回来
import org.yaml.snakeyaml.*
DumperOptions opt = new DumperOptions()
opt.setAllowUnicode(false)
opt.setDefaultFlowStyle(FlowStyle.BLOCK)
Representer rep =  new YamlRepresenter()
rep.setDefaultFlowStyle(FlowStyle.BLOCK)
Yaml yaml = new Yaml(new YamlConstructor(), rep, opt)
Field f = c.getClass().getDeclaredField("yaml")
f.setAccessible(true)
f.set(c, yaml)

然后你save就不会有Unicode了
比较麻烦,但是如果你要用bukkit的配置文件库只能这样

第一页 上一页 下一页 最后一页