ssm框架读取自定义配置文件

匿名 (未验证) 提交于 2019-12-03 00:19:01

配置文件放在resources文件夹里

package com.repWater.Utils;  /**  * Created by Lucy on 2018/5/23.  */  import org.slf4j.Logger; import org.slf4j.LoggerFactory;  import java.io.*; import java.util.Properties;  /**  * Desc:properties文件获取工具类  * Created by hafiz.zhang on 2016/9/15.  */ public class PropertyUtil {     private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class);     private static Properties props;     static{         loadProps();     }      synchronized static private void loadProps(){         props = new Properties();         InputStream in = null;         try {             //in = PropertyUtil.class.getClassLoader().getResourceAsStream("param.properties");             in = PropertyUtil.class.getResourceAsStream("/param.properties");             props.load(in);         } catch (FileNotFoundException e) {             logger.error("jdbc.properties文件未找到");         } catch (IOException e) {             logger.error("出现IOException");         } finally {             try {                 if(null != in) {                     in.close();                 }             } catch (IOException e) {                 logger.error("jdbc.properties文件流关闭出现异常");             }         }      }      public static String getProperty(String key){         if(null == props) {             loadProps();         }         return props.getProperty(key);     }      public static String getProperty(String key, String defaultValue) {         if(null == props) {             loadProps();         }         return props.getProperty(key, defaultValue);     } }  
中文乱码new String(name.getBytes("ISO8859-1"), "UTF-8")

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