I have a file which is encoded as iso-8859-1, and contains characters such as ô .
I am reading this file with java code, something like:
File in = new File("myfile.csv");
InputStream fr = new FileInputStream(in);
byte[] buffer = new byte[4096];
while (true) {
int byteCount = fr.read(buffer, 0, buffer.length);
if (byteCount <= 0) {
break;
}
String s = new String(buffer, 0, byteCount,"ISO-8859-1");
System.out.println(s);
}
However the ô character is always garbled, usually printing as a ? .
I have read around the subject (and learnt a little on the way) e.g.
but still can not get this working
Interestingly this works on my local pc (xp) but not on my linux box.
I have checked that my jdk supports the required charsets (they are standard, so this is no su

该博客讲述了在Java中遇到的问题,即使用ISO-8859-1编码读取含有特殊字符如ô的文件时,字符显示为问号。问题在Windows XP系统上可以正常工作,但在Linux环境下出现乱码。作者建议检查文件实际编码和确认`System.out`是否能正确打印相应字符,并推荐使用`InputStreamReader`以指定编码读取文件。
最低0.47元/天 解锁文章
645

被折叠的 条评论
为什么被折叠?



