Loads all of the properties represented by the XML document on the specified input stream into this properties table.Loads all of the properties represented by the XML document on the specified input stream into this properties table.
Program
package com.candidjava;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
/*
* @author : Mohan
* @description : The java.util.Properties.loadFromXML(InputStream in) method loads all of the properties represented by the XML document on the specified input stream into this properties table.
*/
public class PropertiesLoadXml {
public static void main(String[] args) {
Properties prop = new Properties();
// add some properties
prop.put("Length", "200");
prop.put("Breadth", "15");
try {
// create a output and input as a xml file
FileOutputStream fos = new FileOutputStream("properties.xml");
FileInputStream fis = new FileInputStream("properties.xml");
// store the properties in the specific xml
prop.storeToXML(fos, null);
// load from the xml that we saved earlier
prop.loadFromXML(fis);
// print the properties list
prop.list(System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Output
-- listing properties --
Length=200
Breadth=15
Explanation
public void loadFromXML(InputStream in) throws IOException,InvalidPropertiesFormatException
Loads all of the properties represented by the XML document on the specified input stream into this properties table.
The XML document must have the following DOCTYPE declaration:
Furthermore, the document must satisfy the properties DTD described above.
The specified stream is closed after this method returns.
Parameters:
in - the input stream from which to read the XML document.
Throws:
IOException - if reading from the specified input stream results in an IOException.
InvalidPropertiesFormatException - Data on input stream does not constitute a valid XML document with the mandated document type.