示例代码:
// 将指定路径下的资源文件中的内容以输入流的形式读出来(准备读到程序中)
InputStream inputStream = this.getClass().getResourceAsStream(
"/jp/co/***/sourcing/***.properties");
Properties p = new Properties();
// 从输入流中读取出所有配置信息(键值对形式,存放在Map中)
p.load(inputStream);
// 从该map中获取到指定属性的值
String from = p.getProperty("***_INFO");
java.lang.Class<T>中的方法:
InputStream getResourceAsStream(String name)
Finds a resource with a given name.
20090417分析:根据给定的文件名,拿到该文件的输入流(一根管道接到了该文件上,准备从该文件中往外读数据,向程序中读入内容)。
java.util.Properties中的方法:
void load(InputStream inStream)
Reads a property list (key and element pairs) from the input stream.
20090417分析:从这个输入流中读取出所有的配置信息(属性list,键值对的形式)。