java.util.Properties.storeToXML(OutputStream osString comment)%uA0方法发出代表所有包含在此表中的属性的XML文档。形式如props.storeToXML(os, comment) 这个方法的调用以完全相同的方式表现为调用props.storeToXML(os, comment, "UTF-8")
声明
以下是java.util.Properties.storeToXML()方法的声明
public void storeToXML(OutputStream os,String comment)
参数
-
out%uA0-- 根据其内容发出XML文档的输出流。
-
comments%uA0-- 属性列表,或者为null的描述,如果没有所需的注释。
返回值
这个方法没有任何返回值
异常
-
IOException%uA0--%uA0如果将此属性列表写入到指定的输出流抛出一个IOException异常。
-
ClassCastException%uA0-- 如果此Properties对象包含不属于任何字符串键或值。
-
NullPointerException%uA0-- 如果%uA0out 为%uA0null.
例子
下面的示例演示java.util.Properties.storeToXML()方法的用法。
package com.yiibai 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 prop.storeToXML(fos, "Properties Example") // print the xml while (fis.available() > 0) { System.out.print("" + (char) fis.read()) } } catch (IOException ex) { ex.printStackTrace() } } }
让我们来编译和运行上面的程序,这将产生以下结果:
<?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>