目录

void loadFromXML(InputStream in)

描述 (Description)

java.util.Properties.loadFromXML(InputStream in)方法将指定输入流上的XML文档表示的所有属性加载到此属性表中。

声明 (Declaration)

以下是java.util.Properties.loadFromXML()方法的声明

public void loadFromXML(InputStream in)

参数 (Parameters)

in - 从中读取XML文档的输入流。

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

  • IOException - 如果从指定的输入流读取会导致IOException。

  • InvalidPropertiesFormatException - 输入流上的数据不构成具有强制文档类型的有效XML文档。

  • NullPointerException - 如果in为null。

例子 (Example)

以下示例显示了java.util.Properties.loadFromXML()方法的用法。

package com.iowiki;
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, 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();
      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

-- listing properties --
Width=15
Height=200
↑回到顶部↑
WIKI教程 @2018