首页 > 其他 > 详细

模拟load()方法将指定流中的属性列表加载到properties中

时间:2014-03-10 02:41:56      阅读:520      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class TestDriver {
 
 
    public static void main(String[] args) throws IOException {
        File file = new File("e:\\test.config");
        //模拟load()方法将指定流中的属性列表加载到properties中,指定文件必须是键值对形式
        Properties ps = new Properties();
        BufferedReader bufR = new BufferedReader(new FileReader(file));
        String bufStr = null;
        while((bufStr = bufR.readLine()) != null){
            if(bufStr.startsWith("#")){
                continue;
            }
            String[] strs = bufStr.split("=");
            ps.setProperty(strs[0], strs[1]);
        }
        System.out.println("=================");
        ps.list(System.out);
    }
}

  这就相当于

1
2
3
4
5
6
7
8
9
10
11
12
public class TestDriver {
 
 
    public static void main(String[] args) throws IOException {
        File file = new File("e:\\test.config");
        //load()方法将指定流中的属性列表加载到properties中,指定文件必须是键值对形式
        Properties ps = new Properties();
        System.out.println("=================");
        ps.load(new FileReader(file));
                ps.list(System.out);
    }
}

  

模拟load()方法将指定流中的属性列表加载到properties中,布布扣,bubuko.com

模拟load()方法将指定流中的属性列表加载到properties中

原文:http://www.cnblogs.com/lxricecream/p/3590636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!