package com.tygy.util; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; public class ReadProperties { /** * 文件路徑 */ private static String filePath = "resources/clounm.properties"; /** * 獲取properties文件中的內容,並返回map * * @return */ public static Map<String, String> getProperties() { Map<String, String> map = new HashMap<String, String>(); InputStream in = null; Properties p = new Properties();; try { in = new BufferedInputStream(new FileInputStream(new File(filePath))); p.load(in); } catch (Exception e) { e.printStackTrace(); } Set<Entry<Object, Object>> entrySet = p.entrySet(); for (Entry<Object, Object> entry : entrySet) { map.put((String) entry.getKey(), (String) entry.getValue()); } return map; } }
配置文件
clounm.properties
## 需要執行的SQL語句 sql = select * from table ## 字段對應關系 clounm = id,name ## type type = type
properties文件默認編碼集為iso8859-1,設置為utf-8才可以使用中文注釋