I am trying to parse CSV file with OpenCSV. I have an error while creating new CSVReader "CSVReader() in CSVReader cannot be applied to (Java.io.FileReader, char)". I copied this example from the official page. Why i cannot use a Reader? I have to access a csv file.
我试图用OpenCSV解析CSV文件。创建新CSVReader时出错“CSVReader中的CSVReader()无法应用于(Java.io.FileReader,char)”。我从官方页面复制了这个例子。为什么我不能使用读卡器?我必须访问csv文件。
package csv;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CSVReader {
public static void main(String[] args) throws IOException {
String fileName = "storici/eurusd.csv";
CSVReader reader = new CSVReader(new FileReader(fileName), ',');
List<CSVData> records = new ArrayList<CSVData>();
// read line by line
String[] record = null;
while ((record = reader.readNext()) != null) {
CSVData data = new CSVData();
data.setTime(record[0]);
data.setOpen(record[1]);
data.setHigh(record[2]);
data.setLow(record[3]);
data.setClose(record[4]);
data.setVolume(record[5]);
records.add(data);
}
System.out.println(records);
reader.close();
}
}
1 个解决方案
#1
1
The issue here is that you have called your class CSVReader which *es with the OpenCSV class. I would suggest renaming your class then importing the correct one.
这里的问题是你已经调用了你的类CSVReader,它与OpenCSV类冲突。我建议重命名你的课程然后导入正确的课程。
#1
1
The issue here is that you have called your class CSVReader which *es with the OpenCSV class. I would suggest renaming your class then importing the correct one.
这里的问题是你已经调用了你的类CSVReader,它与OpenCSV类冲突。我建议重命名你的课程然后导入正确的课程。