web项目 读取src下的配置文件
2011-06-26 23:26
495 查看
package com.test;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.Set;
import java.util.Map.Entry;
public class ReadPropertiesFile {
/**
* @param args
*/
public static void main(String[] args) {
Map<String, String> map = ReadPropertiesFile.config();
Set<Entry<String, String>> s = map.entrySet();
for (Entry<String, String> entry : s) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
private static Map<String, String> config() {
Map<String, String> map = new HashMap<String, String>();
// src下的dataConfig.properties配置文件
String fileName = "dataConfig";
// 加载配置文件
PropertyResourceBundle resourceBundle = (PropertyResourceBundle) PropertyResourceBundle
.getBundle(fileName);
// 分解配置文件下的条目至一个枚举
Enumeration<String> enu = resourceBundle.getKeys();
// 组装成java可以识别处理的键值对
while (enu.hasMoreElements()) {
String propertyName = enu.nextElement().toString();
map.put(propertyName, resourceBundle.getString(propertyName));
}
return map;
}
}
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.Set;
import java.util.Map.Entry;
public class ReadPropertiesFile {
/**
* @param args
*/
public static void main(String[] args) {
Map<String, String> map = ReadPropertiesFile.config();
Set<Entry<String, String>> s = map.entrySet();
for (Entry<String, String> entry : s) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
private static Map<String, String> config() {
Map<String, String> map = new HashMap<String, String>();
// src下的dataConfig.properties配置文件
String fileName = "dataConfig";
// 加载配置文件
PropertyResourceBundle resourceBundle = (PropertyResourceBundle) PropertyResourceBundle
.getBundle(fileName);
// 分解配置文件下的条目至一个枚举
Enumeration<String> enu = resourceBundle.getKeys();
// 组装成java可以识别处理的键值对
while (enu.hasMoreElements()) {
String propertyName = enu.nextElement().toString();
map.put(propertyName, resourceBundle.getString(propertyName));
}
return map;
}
}
相关文章推荐
- web项目读取配置文件
- Java web 项目读取src或者tomcat下class目录下的xml文件或者properties文件
- Maven项目中读取src/main/resources目录下的配置文件
- Maven项目中读取src/main/resources目录下的配置文件的方法
- jsp项目读取src目录下的配置文件
- Web项目中java类读取WebRoot目录下的配置文件
- WEB 项目中读取 WEB-INF 目录下配置文件的方法
- Maven项目中读取src/main/resources目录下的配置文件
- 读取web项目中的配置文件
- 读取项目src下等的配置文件,适合于weblogic,tomcat等多种不同的容器。
- web.xml文件加载顺序 一、 1 、启动一个 WEB 项目的时候, WEB 容器会去读取它的配置文件 web.xml ,读取 <listener> 和 <context-param>
- Java Web项目如何读取.properties配置文件
- Maven项目中读取src/main/resources目录下的配置文件
- Java web 项目读取src或者tomcat下class文件夹下的xml文件或者properties文件
- WEB项目加载配置文件并读取配置文件
- java读取配置文件(web项目和java项目都可以)
- Web 项目 中读取专用配置文件
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题
- java WEB 配置文件的读取
- 解决spring-boot项目中无法读取yml配置文件属性问题