标签:font util 文件结构 inpu etc alt str logs png
文件结构目录如图所示:
其中,config2为与src同级的sourec folder,c.properties位于src根目录,b.properties位于src/config1 folder下
a.properties位于cn.package1包下。所有结果均已成功测试,测试环境为Myeclipse2016+JDK8
一、读取a.properties:
1 package cn.package1;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Properties;
6
7 import org.junit.Test;
8
9 public class Demo01 {
10 @Test
11 public void fun1() throws IOException{
12 InputStream in1 = Demo01.class.getClassLoader()
13 .getResourceAsStream("cn/package1/a.properties");
14 Properties props = new Properties();
15 props.load(in1);
16 String value1 = props.getProperty("name");
17 System.out.println(value1);
18 }
19 }
(输入流的处理以及关闭可以改进)
二、读取b.properties:
(重复代码已经省略!)
1 InputStream in1 = Demo01.class.getClassLoader()
2 .getResourceAsStream("config1/b.properties");
三、读取c.properties:
1 InputStream in1 = Demo01.class.getClassLoader()
2 .getResourceAsStream("c.properties");
四、读取d.properties:
InputStream in1 = Demo01.class.getClassLoader()
.getResourceAsStream("d.properties");
标签:font util 文件结构 inpu etc alt str logs png
原文地址:http://www.cnblogs.com/jiangbei/p/6665322.html