java读取properties文件内容

来源:互联网 发布:图片识别字体软件 编辑:程序博客网 时间:2024/06/05 05:01
@Testpublic void test2() throws Exception{//第一种ClassLoader c = this.getClass().getClassLoader();String s ="com\\beijing\\haha\\jdbc.properties";InputStream in = c.getResourceAsStream(s);Properties p = new Properties();p.load(in);System.out.println(p.getProperty("user"));//第二种FileInputStream fi = new FileInputStream(new File("jdbc.properties"));Properties p2 = new Properties();p2.load(fi);System.out.println(p2.getProperty("user"));}
new FIle如果写相对路径的话,那么默认是项目根目录,和src同一路径
0 0
原创粉丝点击