- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Properties loadFromXML() Method
Description
The java Properties loadFromXML(InputStream in) method loads all of the properties represented by the XML document on the specified input stream into this properties table.
Declaration
Following is the declaration for java.util.Properties.loadFromXML() method
public void loadFromXML(InputStream in)
Parameters
in − the input stream from which to read the XML document.
Return Value
This method does not return a value.
Exception
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.
NullPointerException − if in is null.
Loading Properties From an XML File Example
The following example shows the usage of Java Properties loadFromXML(Stream) method to load the properties from a xml file.
package com.tutorialspoint; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class PropertiesDemo { public static void main(String[] args) { Properties prop = new Properties(); // add some properties prop.put("Height", "200"); prop.put("Width", "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
Let us compile and run the above program, this will produce the following result −
-- listing properties -- Height=200 Width=15
To Continue Learning Please Login
Login with Google