public static void writeXml(Path configDir, Path xmlFile) throws IOException, XMLStreamException {
XMLOutputFactory output = XMLOutputFactory.newInstance();
try (Writer writer = Files.newBufferedWriter(xmlFile, StandardCharsets.UTF_8)) {
XMLStreamWriter xmlWriter = output.createXMLStreamWriter(writer);
try {
xmlWriter.writeStartDocument(StandardCharsets.UTF_8.toString(), "1.0");
xmlWriter.writeStartElement("config");
try (DirectoryStream<Path> ds = Files.newDirectoryStream(configDir, entry -> Files.isRegularFile(entry) && entry.getFileName().toString().endsWith(".properties"))) {
for (Path file : ds) {
String fileName = file.getFileName().toString();
String fileNameWithoutExtension = fileName.substring(0, fileName.length() - 11);
xmlWriter.writeStartElement(fileNameWithoutExtension);
Properties properties = new Properties();
try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
properties.load(reader);
}
for (String name : properties.stringPropertyNames()) {
String value = properties.getProperty(name);
xmlWriter.writeStartElement(name);
xmlWriter.writeCharacters(value);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
}
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
} finally {
xmlWriter.close();
}
}
}
PropertiesPlatformConfig.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:powsybl-core
作者:
评论列表
文章目录