java Properties转map
来源:互联网 发布:新天下无双挂机软件 编辑:程序博客网 时间:2024/05/17 20:14
按key读取properties数据
//按key读取properties数据properties.getProperty(key)
properties数据转map
import java.util.Properties;import java.util.Map;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.HashMap;/** * * @author gyn * */@SuppressWarnings("all")public class PropertiesUtil { private final static String PATH=System.getProperty("user.dir"); public static final Map<String, String> PARAMETERS_MAP=PropertiesUtil.getMap("\\src\\main\\resources\\parameters.properties"); static{ Map<String, String> map = PARAMETERS_MAP; for (Map.Entry<String, String> entry : map.entrySet()) { System.out.printf("%s = %s%n", entry.getKey(), entry.getValue()); } } public static void main(String[] args) { } public static Map<String, String> getMap(String path) { Properties properties = new Properties(); properties = readFile(PATH+path); Map<String, String> map = new HashMap<String, String>((Map) properties); return map; } public static Properties readFile(String path) { File file = new File(path); Properties properties = new Properties(); InputStream in = null; try { in = new FileInputStream(file); properties.load(in); in.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return properties; }}
阅读全文
0 0
- java Properties转map
- Java Map接口Properties
- Java 中Map 和 Properties 的遍历
- java类集(List/Set/Map/Iterator)(Enumeration/Vector/Stack/Properties)
- Java集合框架之Map--Hashtable和Properties源码分析
- Java集合之五Map、HashMap、LinkedHashMap、TreeMap、Properties
- Properties 转换成Map
- Properties转换成Map
- Java map转scala map
- Java读取Properties文件-转
- Java读取properties文件 【转】
- Java读取properties文件 【转】
- Java读取properties文件 【转】
- Java读取properties文件 【转】
- (转)java读取properties
- JAVA Properties
- java properties
- java properties
- Ceph安装对象网关
- QT 通用数据库数据导入导出方案
- CentOS7 Shell基础知识
- Vue axios请求PUT/DELETE请求变OPTIONS
- 教您一招解决Word不能复制粘贴问题
- java Properties转map
- 字符集和字符编码
- JBoss启动报错org.hibernate.cfg.annotations.SimpleValueBinder.setType
- DecimalFormat (Java 格式化数字 )
- 正向代理、反向代理
- C++ STL queue小结
- Javascript的this用法
- 使用泛型方法打印不同字符串的元素(泛型例子学习)
- openwrt MT7688开发板 从零教程