3

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

非常感谢你。

4

2 回答 2

5

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

XMLConfiguration config = new XMLConfiguration();
StringWriter stringWriter = new StringWriter();
config.save(stringWriter);
System.out.println(stringWriter.toString());
于 2011-05-15T12:49:01.043 回答
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
于 2011-05-08T20:36:04.990 回答