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