You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ResourceBundle加载越南语properties文件时遇MissingResourceException

问题解决:ResourceBundle加载.properties文件失败

错误原因

  • Locale语言代码不规范:越南语的ISO 639-1标准语言代码是小写的vi,你使用new Locale("Vi")创建的Locale不符合规范,导致ResourceBundle无法匹配正确的属性文件。
  • 文件名与Locale不匹配:ResourceBundle会根据Locale的语言代码(小写)查找对应文件,要求越南语属性文件必须命名为language_vi.properties(后缀为小写),若文件名是大写后缀,会直接导致查找失败。

修复方案

1. 修正Locale创建代码

将越南语Locale的语言代码改为小写的vi:

// 越南语登录版本
private static void VietnameseLogin() { 
    Locale locale = new Locale("vi"); 
    ResourceBundle bundle = ResourceBundle.getBundle("language", locale); 
    Login(bundle); 
}

2. 调整属性文件名

确保越南语属性文件命名为language_vi.properties(后缀为小写的vi),与Locale的语言代码保持一致。

修改完成后,ResourceBundle即可正确加载越南语资源文件;英语版本代码无需调整,因为Locale.ENGLISH对应的language_en.properties文件名符合规范。

内容的提问来源于stack exchange,提问作者TranGiangAnh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 10:40:35