1. 程式人生 > 其它 >2021-01-11-getResourceAsStream中文亂碼-p3c標題名顯示為中文

2021-01-11-getResourceAsStream中文亂碼-p3c標題名顯示為中文

技術標籤:開發

參考:
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); }