一直用一個方法安然無恙,今天在新項目中忽然亂碼了,原代碼:優化
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")); } ……