XMLConfiguration到String

时间:2011-05-08 15:53:40

标签: java xml apache-commons-config

我正在使用Apache Commons配置。如何直接获取XMLConfiguration的字符串而不将其保存到文件中?

非常感谢。

2 个答案:

答案 0 :(得分:5)

我找到了解决方案,可以通过StringWriter:

XMLConfiguration config = new XMLConfiguration();
StringWriter stringWriter = new StringWriter();
config.save(stringWriter);
System.out.println(stringWriter.toString());

答案 1 :(得分:1)

org.apache.commons.configuration.ConfigurationUtils.toString()

  

public static String    toString (配置配置)

Get a string representation of the key/value mappings of a configuration.

Parameters:
    configuration - the configuration 
Returns:
    a string representation of the configuration