So konvertieren Sie eine XML-Datei in eine Eigenschaftendatei - Java
Im letzten Artikel zeigen wir Ihnen, wie manconvert properties file into XML file macht. Siehe folgende XML-Datei:
Support Email [email protected]
In diesem Beispiel zeigen wir Ihnen, wie Sie die MethodeloadFromXML()verwenden, um die obige XML-Datei in ein Eigenschaftenobjekt zu laden und den Schlüsselwert „email.support“ über die MethodegetProperty()
abzurufen.
package com.example; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class PropertiesXMLExample { public static void main(String[] args) throws IOException { Properties props = new Properties(); InputStream is = new FileInputStream("c:/email-configuration.xml"); //load the xml file into properties format props.loadFromXML(is); String email = props.getProperty("email.support"); System.out.println(email); } }
Output
Im obigen Beispiel wird der Wert des Eigenschaftenschlüssels ausgedruckt: "email.support":