【发布时间】:2011-10-23 04:00:01
【问题描述】:
我无法从文件中读取 UTF-8 字符作为字节。 UTF-8 字符在从字节转换为字符时显示为 questionmarak(?)。
下面的代码 sn -p 显示文件读取。
请告诉我如何从文件中读取 UTF-8 字符。 请告诉我字节数组读取过程有什么问题?
public static void getData {
FormFile file = actionForm.getFile("UTF-8");
byte[] mybt;
try
{
byte[] fileContents = file.getFileData();
StringBuffer sb = new StringBuffer();
for(int i=0;i<fileContents.length;i++){
sb.append((char)fileContents[i]);
}
System.out.println(sb.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Output ::??Docum??ents (input file content is : "ÞDocumÿents" , it contains some spanish characters. )
【问题讨论】:
标签: java file-upload