Java Properties .loadFromXML (InputStream in)

Syntax

Properties.loadFromXML(InputStream in) has the following syntax.

public void loadFromXML(InputStream in)   throws IOException ,    InvalidPropertiesFormatException

Example

In the following code shows how to use Properties.loadFromXML(InputStream in) method.


//from   ww  w  . ja  v a2  s.  c om
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

public class Main {

  public static void main(String[] args) throws Exception {
    Properties prop = new Properties();

    prop.put("Chapter Count", "200");
    prop.put("Tutorial Count", "15");

    // 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);

  }
}

The code above generates the following result.