【问题标题】:No values are copied from the default config没有从默认配置中复制任何值
【发布时间】:2012-03-10 16:57:21
【问题描述】:

我已经写了这段代码:

public void reloadDefConfig(File filepath, String fileInJar) {
    File configFile = filepath;
    FileConfiguration daConfig = YamlConfiguration.loadConfiguration(configFile);

    if (!configFile.exists()){
        log.info(logName + "Creating default \"" + fileInJar + "\".");

        InputStream defConfigStream = getResource(fileInJar);

        if (defConfigStream != null){
            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
            daConfig.setDefaults(defConfig);

            try {
                daConfig.save(configFile);
                log.info(logName + "Default config file \"" + fileInJar + "\" wrote.");
            } catch (IOException ex){
                log.severe(logName + "Could not write config file: " + fileInJar);
            }
        } else {
            log.warning(logName + "Could not find default \"" + fileInJar + "\" file.");
        }
    }
}

为了在 JAR 中获取这个 config.yml 文件并输出它:

# Home section; this next part of code decides how large the radius to check for monsters
#  for the /home command if not set it will be auto default to 10x10x10 if you want to 
#  disable the radius use -1 on the value (note one value with -1 will disable all)
  home:
    x: 10
    y: 10
    x: 10

但是当我这样称呼它时:

reloadDefConfig(new File(getDataFolder(), "config.yml"), "config.yml");

没有值被复制:

# Home section; this next part of code decides how large the radius to check for monsters
#  for the /home command if not set it will be auto default to 10x10x10 if you want to 
#  disable the radius use -1 on the value (note one value with -1 will disable all)

【问题讨论】:

    标签: java yaml bukkit


    【解决方案1】:

    一种可能性是home: 之前有两个空格。 尝试摆脱它们或添加父节点,因此生成的文件如下所示:

    # Home section; this next part of code decides how large the radius to check for monsters
    #  for the /home command if not set it will be auto default to 10x10x10 if you want to 
    #  disable the radius use -1 on the value (note one value with -1 will disable all)
    Main:
      home:
        x: 10
        y: 10
        x: 10
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 1970-01-01
      • 2012-08-23
      • 2015-10-11
      • 1970-01-01
      • 2020-09-02
      • 2020-03-21
      相关资源
      最近更新 更多