一直用一个方法安然无恙,今天在新项目中突然乱码了,原代码:

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        
        InputStream is = null;
        is = classLoader.getResourceAsStream("config/constant.properties");
        if (is != null) 
        {
            try
            {
                props.load(is);
            }

 

 

优化后:

    static  
    {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        
        InputStream is = null;
        is = classLoader.getResourceAsStream("config/constant.properties");
        if (is != null) 
        {
            try
            {
                props.load(new InputStreamReader(is,"UTF-8"));
            }
……

   

相关文章:

  • 2021-12-27
  • 2021-04-13
  • 2021-10-08
猜你喜欢
  • 2021-08-24
  • 2021-11-19
  • 2021-09-07
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案