我正在尝试使用以下代码从 .properties 文件中读取日语字符串值:
Properties properties = new Properties();
InputStream in = MyClass.class.getResourceAsStream(fileName);
properties.load(in);
问题显然是上面的代码无法识别文件的编码。它只读取英文部分并用问号替换日文字符。顺便说一下,这不是在 Swing 中显示日文文本或读/写在编辑器中 UTF-8 编码的 .properties 文件的问题。两者都有效。
Properties
类是否编码未知?是否存在不违反通常在小程序中找到的安全管理器设置的编码感知替代方案?
最佳答案
在我看来,你必须将日文字符转换为 java Unicode 转义字符串
例如,这是我对越南语的处理方式
Currency_Converter = Chuyen doi tien te
Enter_Amount = Nh\u1eadp v\u00e0o s\u1ed1 l\u01b0\u1ee3ng
Source_Currency = \u0110\u01a1n v\u1ecb g\u1ed1c
Target_Currency = \u0110\u01a1n v\u1ecb chuy\u1ec3n
Converted_Amount = K\u1ebft qu\u1ea3
Convert = Chuy\u1ec3n \u0111\u1ed5i
Alert_Mess = Vui l\u00f2ng nh\u1eadp m\u1ed9t s\u1ed1 h\u1ee3p l\u1ec7
Alert_Title = Thong bao
关于java - Java .properties 文件中的日语文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8416680/