Java.util.Properties.load() 方法
描述
java.util.Properties.load(Reader reader) 方法以简单的面向行的格式从输入字符流中读取属性列表(键和元素对)。
声明
以下是 java.util.Properties.load() 方法的声明
public void load(Reader reader)
参数
reader − 输入字符流。
返回值
此方法不返回值。
异常
IOException − 如果从输入流读取时发生错误。
IllegalArgumentException − 如果输入流包含格式错误的 Unicode 转义序列。
示例
下面的例子展示了 java.util.Properties.list() 方法的使用。
package com.tutorialspoint;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
public class PropertiesDemo {
public static void main(String[] args) {
Properties prop = new Properties();
String s = "Height=200\nWidth=15";
// create a new reader
StringReader reader = new StringReader(s);
try {
// load from input stream
prop.load(reader);
// print the properties list from System.out
prop.list(System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
-- listing properties -- Width=15 Height=200

