2021-01-11-getResourceAsStream中文亂碼-p3c標題名顯示為中文
阿新 • • 發佈:2021-01-12
技術標籤:開發
參考:
https://blog.csdn.net/weixin_33881041/article/details/94735867
try (InputStream stream = PmdRulesDefinition.class.getResourceAsStream("/org/sonar/l10n/pmd.properties")) {
properties.load(stream);
} catch (IOException e) {
throw new IllegalArgumentException("Could not read names from properties" , e);
}
優化後
try (InputStream stream = PmdRulesDefinition.class.getResourceAsStream("/org/sonar/l10n/pmd.properties")) {
// 解決 p3c 中文標題亂碼問題
properties.load(new InputStreamReader(stream, StandardCharsets.UTF_8));
} catch (IOException e) {
throw new IllegalArgumentException("Could not read names from properties" , e);
}