import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* 读取.properties配置文件的内容至Map中
* @author libo
*
*/
public class PropertiesUtil {
/**
* 读取.properties配置文件的内容至Map
* @param propertiesFile
* @return
* @throws IOException
*/
public static Map read(String propertiesFile) {
try {
// PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//
// Resource resouces[] = resolver.getResources(propertiesFile);
if (!(propertiesFile.indexOf("properties") >0))
{
propertiesFile = propertiesFile + ".properties";
}
InputStream inStream =Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFile);
Properties p = new Properties();
p.load(inStream);
Map<Object,Object> map = properties2map(p);
return map;
} catch (IOException e) {
throw n
读取.properties配置文件的内容至Map中
最新推荐文章于 2023-04-25 10:45:27 发布
本文详细讲解如何在Java中将.properties配置文件的内容加载到Map对象中,包括使用Properties类的方法,以及相关注意事项。

最低0.47元/天 解锁文章
652

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



