作者:wgsd325 | 来源:互联网 | 2023-05-17 11:54
所有中文写在文件:WebFileLabels_zh_CN.properties中如:5000文件5001文件夹5002保存5003上载5004剪切5005复制
所有中文写在文件:WebFileLabels_zh_CN.properties中 如:
5000=文件
5001=文件夹
5002=保存
5003=上载
5004=剪切
5005=复制
5006=粘贴
5007=删除
5008=重命名
5009=新文件
在类中写到:
ResponseWriteLn("ftarget.write('
');");
ResponseWriteLn("ftarget.write(' '); ");
ResponseWriteLn("ftarget.write('');");
ResponseWriteLn(String.valueOf((new StringBuffer("ftarget.write('")).append(labels.getString("5009")).append("');")));//这里调用了上面文件中对应的5009
ResponseWriteLn("ftarget.write('');");
ResponseWriteLn("ftarget.write('');");
ResponseWriteLn("ftarget.write(' | ');");
但是我用javac -encoding ISO8859_1 编译还是不能显示中文,请问要如何处理呢
6 个解决方案
从.properties文件取值时,需要进行字节转换!才能显示中文
要如何做,代码写在哪,xmvigour(微电) 快帮忙
ResourceBundle rb = ResourceBundle.getBundle("lwz");
String author = GB2Unicode(rb.getString("lwz.author"));
public static String GB2Unicode(String s) {
if(s == null)
{
return s;
}
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i dest[i] = (byte)(orig[i]&0xFF);
try
{
ByteToCharConverter toChar = ByteToCharConverter.getConverter("GBK");
return new String(toChar.convertAll(dest));
}
catch (Exception e)
{
System.out.println(e);
return s;
}
}
那是我前端时间,大概七八月在家度假时,自己摸索,当然也是在网上找相关资料才搞定的!
希望大家共同进步!!