web 项目中,当用到一些用户名、密码等可变属性时,尽量使用properties格式的文件存放。下面说明一下如何在项目读取配置文件:
这只是一种方式,还有其他方式可以读取
<span style="font-size:14px;">private static Properties prop = new Properties();
</span><pre name="code" class="java"><span style="font-size:14px;">static {
InputStream in = ClassName.class.getResourceAsStream(path of properties);
prop.load(in);
String str1 = prop.getProperty(key1);
String str2 = prop.getProperty(key2);
......
}
</span>