简体   繁体   English

在java中读取csv文件

[英]Csv file reading in java

My program is to read values from a csv file.I am to totally confused with the following part of code in my program reader.readHeaders() and reader.readRecord() (these methods are undescribed in my eclipse) methods in java....Because it showing me errors.我的程序是从 csv 文件中读取值。我完全与我的程序reader.readHeaders()reader.readRecord()的以下代码部分混淆(这些方法在我的 eclipse 中未描述)java 中的方法.. ..因为它向我展示了错误。 Is there any jar files need to be added to my program?是否需要将任何 jar 文件添加到我的程序中?

try {
    System.out.println("file name"+fileName);
    CsvReader products = new CsvReader("categories/"+fileName);        
    products.readHeaders(); //I'm getting an error here

    while (products.readRecord()) { //I'm also getting an  error here
       //code is here...
    }

The jarfiles that I already added is that我已经添加的 jarfiles 是

  1. opencsv-2.2.jar
  2. javacsv.jar

wrong method readHeaders(), this is for com.csvreader.CsvReader, you are using opencvs "com.opencsv.CSVReader" the method is readNextSilently().错误的方法 readHeaders(),这是针对 com.csvreader.CsvReader,您使用的是 opencvs“com.opencsv.CSVReader”,方法是 readNextSilently()。 so your problems is methods for a different dependency.所以你的问题是不同依赖的方法。https://mvnrepository.com/artifact/com.opencsv/opencsv/5.5.2https://mvnrepository.com/artifact/com.opencsv/opencsv/5.5.2

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

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