【发布时间】:2014-09-19 00:27:50
【问题描述】:
我想将一些希腊文本从 UTF-8 转换为字符串,因为 Java 无法识别它们。然后,我想将它们填充到 JTable 中。所以我使用 List 来帮助我。下面我有代码sn-p:
String[][] rowData;
List<String[]> myEntries;
//...
try {
this.fileReader = new FileReader("D:\\Book1.csv");
this.reader = new CSVReader(fileReader, ';');
myEntries = reader.readAll();
//here I want to convert every value from UTF-8 to String
convertFromUTF8(myEntries); //???
this.rowData = myEntries.toArray(new String[0][]);
} catch (FileNotFoundException ex) {
Logger.getLogger(VJTable.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(VJTable.class.getName()).log(Level.SEVERE, null, ex);
}
//...
我创建了一个方法
public String convertFromUTF8(List<String[]> s) {
String out = null;
try {
for(String stringValues : s){
out = new String(s.getBytes("ISO-8859-1"), "UTF-8");
}
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
但我无法继续,因为 List 没有 getBytes() 方法。 我该怎么办。任何想法都会非常有帮助。提前谢谢你。
【问题讨论】:
-
那么,我必须将 UTF-8 转换为 UTF-16 吗?
-
另外,Java 实现确实支持 UTF-8。是什么让您相信它们不被 Java 认可?有什么错误,坏字符吗?
-
坏字符..它返回矩形而不是字母...
-
您用来查看的工具可能不支持 UTF-8。
-
像 NetBeans 工具还是像 JTable 工具这样的工具?我应该如何让它识别 UTF-8?
标签: java string utf-8 character-encoding