【发布时间】:2011-12-03 16:04:17
【问题描述】:
这是我的问题。我现在使用 Java Apache POI 来读取 Excel(.xls 或 .xlsx)文件,并显示内容。电子表格中有一些日文字符,我得到的所有日文字符都是“???”在我的输出中。我尝试过使用Shift-JIS、UTF-8等多种编码方式,但都不行…… 下面是我的编码代码:
public String encoding(String str) throws UnsupportedEncodingException{
String Encoding = "Shift_JIS";
return this.changeCharset(str, Encoding);
}
public String changeCharset(String str, String newCharset) throws UnsupportedEncodingException {
if (str != null) {
byte[] bs = str.getBytes();
return new String(bs, newCharset);
}
return null;
}
我将得到的每个字符串都传递给 encoding(str)。但是当我打印返回值时,它仍然是“???” (如下所示)但不是日文字符(平假名、片假名或汉字)。
title-jp=???
谁能帮我解决这个问题?非常感谢。
【问题讨论】:
-
您如何“检查”结果? Windows cmdline 无法显示国际字符。 (例如,除非正确设置了语言环境,否则通常不会安装字体)