java iso-8859-1,Java应用程序:无法正确读取iso-8859-1编码文件

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

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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值