我如何使用snakeyaml作为返回某些东西的函数?

时间:2012-04-14 13:44:28

标签: java yaml snakeyaml

我正在尝试使用snakeyaml创建一个转储int,字符串和字符串[]的函数。问题是我不知道如何编写函数以便插入信息。

例如:

public void testDump() {
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("name", "Silenthand Olleander");
    data.put("race", "Human");
    data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });
    Yaml yaml = new Yaml();
    String output = yaml.dump(data);
    System.out.println(output);
}

我需要"name""Silenthand Olleander"这样的内容才能配置。我也不确切知道这个功能是做什么的。它会创建一个新文件吗?因为我需要它来为现有的strings.yml文件添加一行。所以我希望string.yml的格式如下:

#String.yml file
0 name_here The array of argument messages here.
1 name_here Another array of argument messages here.
2 name_here And again... I think you get the point.

1 个答案:

答案 0 :(得分:0)

由于代码(最终)来自documentation,我假设你已经阅读过了。

调用yaml.dump()不会创建文件,而是返回一个字符串(然后您可以put into a file)。根据文档,dump方法将正确处理列表/数组。

要使HashTable中的键(例如“name”)可配置,您可以将所需的值传递给填充表的函数。

基于你的问题,虽然看起来你需要一个关于如何用Java本身编程的速成课程,然后才应该解决snakeyaml。

相关问题