opencsv-2.3.jar解决有中文内容的CSV文件时,代码读取时乱码。
解决方案如下:重构opencsv-2.3.jar包里的CSVReader文件。
方法:
public CSVReader(Reader paramReader, char paramChar1, char paramChar2,
char paramChar3, int paramInt, boolean paramBoolean1,
boolean paramBoolean2) throws UnsupportedEncodingException,
FileNotFoundException {
//br,读取文件流,在此处要给文件编码以解决中文乱码,用以下代码段替代下方代码。
//this.br = new BufferedReader(new InputStreamReader(new FileInputStream(csvFileName), "GBK"));
//csvFileName是文件的全路径
this.br = new BufferedReader(paramReader);
this.parser = new CSVParser(paramChar1, paramChar2, paramChar3,
paramBoolean1, paramBoolean2);
this.skipLines = paramInt;
}
手机扫一扫,关注程序员技能成长