关于上次图片上传的博客。有朋友问到工具类!PropertiesUtil

匿名 (未验证) 提交于 2019-12-03 00:25:02
package com.cxlm.card_god.cardgod_web.utils;   import org.slf4j.Logger; import org.slf4j.LoggerFactory;   import java.io.IOException; import java.io.InputStream; import java.util.Properties;   /**  * Created by Mr.LuoShiDa on 2018/3/1.  */   /**  * Desc:properties文件获取工具类  * Created by Mr.LuoShiDa on 2018/3/1.  */ public class PropertiesUtil {     private static final Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);         /***      * 根据文件名、key读取value      * @param propertiesName      * @param key      * @return      * @throws Exception      */     public static String getProperty(String propertiesName, String key) {         String propertyValue = null;         try {             Properties properties = new Properties();             // 使用ClassLoader加载properties配置文件生成对应的输入流             InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream("properties/" + propertiesName + ".properties");             // 使用properties对象加载输入流             properties.load(in);             //获取key对应的value值             propertyValue = properties.getProperty(key);         } catch (IOException e) {             logger.error("读取[" + propertiesName + "].properties文件中的key为:" + key + ",异常...");             e.printStackTrace();         }         return propertyValue;     }   }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!