一、配置文件config.properties是放在src根目录下的:例如我的是
/PropertiesTest/src/com/xuliugen/project/type.properties
配置文件中的内容如下:
left=com.sunny.project.LeftHair
right=com.sunny.project.RightHair
in=com.sunny.project.InHair 读取配置文件中的代码如下:
public class PropertiesReader {
public static void main(String[] args) {
new PropertiesReader().getProperties();
}
public Map<String, String> getProperties() {
Properties props = new Properties();
Map<String, String> map = new HashMap<String, String>();
try {
InputStream in = getClass().getResourceAsStream("type.properties");
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String property = props.getProperty(key);
map.put(key, property);
System.out.println(key + " " + property);
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
}
本文标题:Java语言读取配置文件config.properties
本文链接:https://blog.quwenai.cn/post/3757.html
版权声明:本文不使用任何协议授权,您可以任何形式自由转载或使用。





![[并发编程] - Executor框架#ThreadPoolExecutor源码解读02 [并发编程] - Executor框架#ThreadPoolExecutor源码解读02](https://blog.quwenai.cn/zb_users/upload/2022/03/20220327124158164835611866353.png)

还没有评论,来说两句吧...