Classes获取文件小结

来源:互联网 发布:java.long.ill 编辑:程序博客网 时间:2024/06/15 11:10

Demo读取properties方式

1.

String p1 = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"\\database.properties";
               Properties p2 = new Properties();
               FileReader fr = new FileReader(new File(p1));
               p2.load(fr);

2.

Properties pro = new Properties();//database.properties
            InputStream in = this.getClass().getClassLoader()
                    .getResourceAsStream("database.properties");
            pro.load(in);

3.通过apache的组件

Configuration  config = new PropertiesConfiguration("database.properties");


原创粉丝点击