如何使用snakeyaml作为返回内容的函数?
我正在尝试使用snakeyaml函数来转储一个int,一个字符串和一个字符串[]。事情是我不知道如何编写函数,以便可以插入信息。如何使用snakeyaml作为返回内容的函数?
例如:
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.
正如代码(最终)来自documentation,我假设你已经阅读了。
呼叫yaml.dump()
不创建文件,而是返回一个字符串(然后您可以put into a file)。根据文档,dump
方法将正确处理列表/数组。
要使HashTable中的键(例如“name”)可配置,可以将所需的值传递给填充表的函数。
根据你的问题,尽管看起来你需要一个关于如何在Java中进行编程的应用程序,然后再解决snakeyaml问题。
我认为它的Map
你应该养成阅读文档的习惯:它可以为你节省麻烦,因为这似乎是随机出现的错误。至于HashMap,做什么是你的困惑的根源? – Attila 2012-04-14 14:05:25
@ T.J.Crowder固定。 – VinylScratch 2012-04-14 13:50:37