java读取properties文件,获取路径的方法

一:

//获取properties对象

Properties prop=new Properties();

InputStream in=Object.class.getResourceAdAtream("/test.properties");

InputStream in=this.class.getResourceAdAtream("/test.properties");

二:

//获取当前类所在的包

File fileB = new File(this.getClass().getResource("").getPath());

三:

//获取当前类所在的工程名

System.getProperties("");

四:

//利用反射方式获取路径

InputStream ips1 = Enumeration.class.getClassLoader() .getResourceAsStream("cn/zhao/enumStudy/testPropertiesPath1.properties");

        

InputStream ips2 = Enumeration.class.getResourceAsStream("testPropertiesPath1.properties");

        

InputStream ips3 = Enumeration.class.getResourceAsStream("properties/testPropertiesPath2.properties");

 

 备注:参考自AllenZhao的博客

 

posted @ 2013-11-04 11:39  esther&  阅读(432)  评论(0)    收藏  举报