how to read utf-8 chars in opencsv

非 Y 不嫁゛ 提交于 2019-12-08 11:45:06

问题


I am trying to read from csv file. The file contains UTF-8 characters. So based on Parse CSV file containing a Unicode character using OpenCSV and How read Japanese fields from CSV file into java beans? I just wrote

CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream("data.csv"), "UTF-8"), ';');

But it does not work. The >>Sí, es nuevo<< text is visible correctly in Notepad, Excel and various other text editing tools, but when I parse the file via opencsv I'm getting >>S�, es nuevo<< ( The í is a special character if you were wondering ;)

What am I doing wrong?


回答1:


Thanks aioobe. It turned out the file was not really UTF-8 despite most Win programs showing it as such. Notepad++ was the only one that did not show the file as UTF-8 encoded and after converting the data file the code works.




回答2:


Use the below code for your issue it might helpful to you...

String value = URLEncoder.encode(msg[no], "UTF-8");

thanks, Yash




回答3:


Use ISO-8859-1 or ISO-8859-14 or ISO-8859-15 or ISO-8859-10 or ISO-8859-13 or ISO-8859-2 instead of using UTF-8




回答4:


you can use encoder=UTF-16LE,I'm write a file for Japanese



来源:https://stackoverflow.com/questions/11612179/how-to-read-utf-8-chars-in-opencsv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!