[b]properties文件读取[/b]
public class PropertiesUtil {
private static final LoggerAdapter logger = LoggerAdapterFactory
.getLogger(MTPLogType.WEB);
/**
* 读取properties文件,返回Map
* @param resourceFileName
* @return
*/
public static Map<String, String> loadFile(String resourceFileName) {
Map<String, String> data = new HashMap<String, String>();
InputStream is = null;
try {
is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(resourceFileName);
Properties properties = new Properties();
properties.load(is);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
data.put((String) entry.getKey(), (String) entry.getValue());
}
return data;
} catch (Exception e) {
logger.error("load "+resourceFileName+" error", e);
return null;
} finally {
if (is != null) {
try {
is.close();
is = null;
} catch (IOException e) {
logger.error("", e);
}
}
}
}
}

本文介绍了一种使用Java读取Properties文件的方法,并将其内容转换为Map数据结构以方便后续操作。
2440

被折叠的 条评论
为什么被折叠?



