读取propeities配置文件

 1  public static Properties readProperties(String fileName) {
 2         InputStream inputStream = PropertiesReader.class.getClassLoader().getResourceAsStream(fileName);
 3         Properties config = new Properties();
 4         try {
 5             config.load(inputStream);
 6         } catch (IOException e) {
 7             LogUtils.logException(e);
 8         } finally {
 9             if (inputStream != null) {
10                 try {
11                     inputStream.close();
12                 } catch (IOException e) {
13                     e.printStackTrace();
14                 }
15             }
16         }
17         
18         return config;
19     }
public static final Map<String, String> ENCODER = new HashMap<String, String>();
1  Properties deviceOtherProperties = PropertiesReader.readProperties("constants/device/device-other-default.properties");
2         for (Map.Entry<Object, Object> entry : deviceOtherProperties.entrySet()) {
3             ENCODER.put(String.valueOf(entry.getKey()), entry.getValue().toString());
4         }
5         importChannelMaxNum = Integer.parseInt(ENCODER.get("encoder.importChannelMaxNum"));
6         importEncoderMaxNum = Integer.parseInt(ENCODER.get("encoder.importEncoderMaxNum"));
7         batchAddChannelMaxNum = Integer.parseInt(ENCODER.get("encoder.batchAddChannelMaxNum"));

猜你喜欢

转载自www.cnblogs.com/xjatj/p/9446970.html