首页javapropertiesJava Collection - 如何存储属性作为XML文件

Java Collection - 如何存储属性作为XML文件

我们想知道如何存储属性作为XML文件。
import java.io.FileOutputStream;
import java.util.Properties;

public class Main {
  public static void main(String[] args) throws Exception {
    Properties properties = new Properties();
    properties.setProperty("database.type", "mysql");
    properties.setProperty("database.url", "jdbc:mysql://localhost/mydb");
    properties.setProperty("database.username", "root");
    properties.setProperty("database.password", "root");

    FileOutputStream fos = new FileOutputStream("database-configuration.xml");
    properties.storeToXML(fos, "Database Configuration", "UTF-8");
  }
}