- 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.util.Properties.storeToXML() Method
Description
The java.util.Properties.storeToXML(OutputStream osString comment,String encoding) method emits an XML document representing all of the properties contained in this table, using the specified encoding.
Declaration
Following is the declaration for java.util.Properties.storeToXML() method
public void storeToXML(OutputStream os,String comment, String encoding)
Parameters
out − the output stream on which to emit the XML document.
comments − a description of the property list, or null if no comment is desired.
Return Value
This method does not return a value
Exception
IOException − if writing this property list to the specified output stream throws an IOException.
ClassCastException − if this Properties object contains any keys or values that are not Strings.
NullPointerException − if out is null.
Example
The following example shows the usage of java.util.Properties.storeToXML() method.
package com.tutorialspoint; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.*; 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 and a different encoding prop.storeToXML(fos, "Properties Example","ISO 8859"); // print the xml. Notice that ISO 8859 isn't supported while (fis.available() > 0) { System.out.print("" + (char) fis.read()); } } catch (IOException ex) { ex.printStackTrace(); } } }
Let us compile and run the above program, this will produce the following result −
Warning: The encoding 'ISO 8859' is not supported by the Java runtime. Warning: encoding "ISO 8859" not supported, using UTF-8 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>Properties Example</comment> <entry key="Width">15</entry> <entry key="Height">200</entry> </properties>