简体   繁体   English

如何在opencsv中读取utf-8字符

[英]how to read utf-8 chars in opencsv

I am trying to read from csv file. 我正在尝试从csv文件读取。 The file contains UTF-8 characters. 该文件包含UTF-8字符。 So based on Parse CSV file containing a Unicode character using OpenCSV and How read Japanese fields from CSV file into java beans? 因此,基于使用OpenCSV解析包含Unicode字符的CSV文件的方法,以及如何将CSV文件中的日语字段读入Java Bean? 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 ;) >>Sí,es nuevo <<文本在记事本,Excel和其他各种文本编辑工具中正确可见,但是当我通过opencsv解析文件时,我得到>> S。,es nuevo <<(í是一个特殊字符,如果您想知道;)

What am I doing wrong? 我究竟做错了什么?

Thanks aioobe. 谢谢aioobe。 It turned out the file was not really UTF-8 despite most Win programs showing it as such. 事实证明,尽管大多数Win程序都显示了该文件,但该文件并不是真正的UTF-8。 Notepad++ was the only one that did not show the file as UTF-8 encoded and after converting the data file the code works. Notepad ++是唯一一个不以UTF-8编码显示文件的文件,并且在转换数据文件后代码可以工作。

Use the below code for your issue it might helpful to you... 将以下代码用于您的问题,可能对您有帮助...

String value = URLEncoder.encode(msg[no], "UTF-8"); 字符串值= URLEncoder.encode(msg [no],“ UTF-8”);

thanks, Yash 谢谢,亚什

使用ISO-8859-1或ISO-8859-14或ISO-8859-15或ISO-8859-10或ISO-8859-13或ISO-8859-2代替UTF-8

你可以使用编码器= UTF-16LE,我用日语写一个文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM