1. 程式人生 > >java 解析csv檔案例子,csv檔案 中文亂碼問題

java 解析csv檔案例子,csv檔案 中文亂碼問題

java 解析csv檔案例子,採用了第三方包,csv檔案 中文亂碼問題

解析方法:

public List resolveCsv(String csvFileName) {
  CSVReader reader = null;
  String[] nextLine = null;
  List resolve = new ArrayList();
  try {
   reader = new CSVReader(new FileReader(csvFileName));
   while ((nextLine = reader.readNext()) != null) {
    if (nextLine != null) {
     resolve.add(nextLine);
    }
   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
  return resolve;
 }

附件中是 第三方包的原始碼,我有改動,

改動的地方:由原來的輸入一個Reader 改成了,輸入引數變為檔案路徑,這樣解決了csv檔案 中文亂碼問題

  • 下載次數: 114