XMLConfiguration到String

Tho*_*mas 3 java xml apache-commons-config

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

非常感谢你.

Tho*_*mas 5

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

XMLConfiguration config = new XMLConfiguration();
StringWriter stringWriter = new StringWriter();
config.save(stringWriter);
System.out.println(stringWriter.toString());
Run Code Online (Sandbox Code Playgroud)