So konvertieren Sie eine Eigenschaftendatei in eine XML-Datei - Java
Viele Entwickler kennen diese Funktion möglicherweise nicht. Tatsächlich enthält die Klassejava.util.Propertieseine MethodestoreToXML(), mit der vorhandene Eigenschaftendaten in eine XML-Datei konvertiert werden können.
Note
Weitere Informationen finden Sie inProperties JavaDoc.
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
public class PropertiesXMLExample
{
public static void main(String[] args) throws IOException
{
Properties props = new Properties();
props.setProperty("email.support", "[email protected]");
//where to store?
OutputStream os = new FileOutputStream("c:/email-configuration.xml");
//store the properties detail into a pre-defined XML file
props.storeToXML(os, "Support Email","UTF-8");
System.out.println("Done");
}
}
Im obigen Beispiel wird das Eigenschaftendetail in eine XML-Datei „c:/email-configuration.xml“ geschrieben.
Support Email
[email protected]