classLoader.getResourceAsStream中文亂碼

  一直用一個方法安然無恙,今天在新項目中忽然亂碼了,原代碼:優化

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

 

 

優化後:spa

    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"));
            }
……
相關文章
相關標籤/搜索