opencsv

Read large CSV in java

让人想犯罪 __ 提交于 2019-12-01 06:38:54
I want to read huge data from CSV, containing around 500,000 rows. I am using OpenCSV library for it. My code for it is like this CsvToBean<User> csvConvertor = new CsvToBean<User>(); List<User> list = null; try { list =csvConvertor.parse(strategy, new BufferedReader(new FileReader(filepath))); } catch (FileNotFoundException e) { e.printStackTrace(); } Upto 200,000 records,data is read into list of User bean objects. But for data more than that I am getting java.lang.OutOfMemoryError: Java heap space I have this memory setting in "eclipse.ini" file -Xms256m -Xmx1024m I am thinking a solution

Read large CSV in java

被刻印的时光 ゝ 提交于 2019-12-01 03:50:12
问题 I want to read huge data from CSV, containing around 500,000 rows. I am using OpenCSV library for it. My code for it is like this CsvToBean<User> csvConvertor = new CsvToBean<User>(); List<User> list = null; try { list =csvConvertor.parse(strategy, new BufferedReader(new FileReader(filepath))); } catch (FileNotFoundException e) { e.printStackTrace(); } Upto 200,000 records,data is read into list of User bean objects. But for data more than that I am getting java.lang.OutOfMemoryError: Java

Skip first line using Open CSV reader

不问归期 提交于 2019-12-01 02:35:35
Here is the line i am using currently File booleanTopicFile; // booleanTopicFile is csv file uploaded from form CSVReader csvReader = new CSVReader(new InputStreamReader(new FileInputStream(booleanTopicFile), "UTF-8")); Want to skip the first line of the csv which contains headings. I dont want to use any separator as except the default one comma(,) which is already available in default constructor. In parameterized constructor there is a option to skip no. of lines but how to deal with the 2nd and 3rd param of the constructor. CSVReader csvReader = new CSVReader(new InputStreamReader(Reader

OpenCSV CSV to JavaBean

对着背影说爱祢 提交于 2019-12-01 01:08:23
If I have a class with non-primitive public members and I want to populate them from a CSV file with OpenCSV, how can I do this? I notice that OpenCSV has some protected members relating to PropertyDescriptors So let's say I have a Person class that has an Address member, and my CSV file contains the detailsd for each person including their address.. Person{ private String name; private Address al public void setAddress(Address a){..} public void setName(String name){..} } Addess{ private String line1; private String line2; private String postCode; . . . } CSV file: NAME | ADDR1 | ADDR2 |

How to read a string containing a '\' using opencsv?

落花浮王杯 提交于 2019-11-30 23:53:04
问题 When I'm reading a csv-file using opencsv it doesn't work properly when encountering a '\' at the end of a string. It makes the " part of the string, instead of the '\' as I want to. I guess there must be some method to add another '\' to have it escape the '\'-character instead? Without having to manually edit the csv-file. I have searched but not found anything. To clarify my problem, it looks like this: csv-file "A", "B", "C", "D" "value 1", "value 2", "value 3", "value 4" "value 5",

IndexError: list index out of range - python

岁酱吖の 提交于 2019-11-30 23:15:53
I have the following error: currency = row[0] IndexError: list index out of range Here is the code: crntAmnt = int(input("Please enter the amount of money to convert: ")) print(currencies) exRtFile = open ('exchangeRate.csv','r') exchReader = csv.reader(exRtFile) crntCurrency = input("Please enter the current currency: ") validateloop=0 while validateloop == 0: for row in exchReader: currency = row[0] if currency == crntCurrency: crntRt = row[1] validateloop=+1 Heres the CSV file: Japanese Yen,169.948 US Dollar,1.67 Pound Sterling,1 Euro,5.5 Here's an input/Output example: Please enter the

openCSV not reading my entire file

折月煮酒 提交于 2019-11-30 20:57:24
I have an application in Java that I am using openCSV to read a file (very large). I am then putting the 4th (Eventually this will have another column or two added if that makes a difference) column into a HashSet and outputting that to a new file. This all seems to work fine but I discovered it is only reading part of the file (131,544 lines of 272,948). Is this a limitation of the openCSV or Java in general or is there a way to get around this? My code for reference: public static void main(String[] args) throws IOException { String itemsFile = new String(); String outFile = new String();

IndexError: list index out of range - python

戏子无情 提交于 2019-11-30 18:45:12
问题 I have the following error: currency = row[0] IndexError: list index out of range Here is the code: crntAmnt = int(input("Please enter the amount of money to convert: ")) print(currencies) exRtFile = open ('exchangeRate.csv','r') exchReader = csv.reader(exRtFile) crntCurrency = input("Please enter the current currency: ") validateloop=0 while validateloop == 0: for row in exchReader: currency = row[0] if currency == crntCurrency: crntRt = row[1] validateloop=+1 Heres the CSV file: Japanese

java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils

ぃ、小莉子 提交于 2019-11-29 13:56:44
I'm trying to code a program to read a CSV file and then make some stuff with it. I've searching a lot, and finally I found out this library. Some days ago I finished the code, and everything worked fine. Today I updated the library to the 4.0 v, and then a lot of warnings popped out. I made some testing and the part that fails is: public void LeerCSV(File CSVCat, File CSVProd){ //Creo un objeto de la clase FileReader que me hace falta para los CSVReader CSVReaderBuilder lectorCatBuilder = null; CSVReaderBuilder lectorProdBuilder = null; CSVReader CatReader = null; CSVReader ProdReader = null;

OpenCsv writes wrong column names with BeanToCsv + HeaderColumnNameTranslateMappingStrategy

妖精的绣舞 提交于 2019-11-29 11:03:02
I'm using opencsv 3.6 in order to create a csv file starting from a java bean. First of all, I tried this code: import com.opencsv.CSVReader; import com.opencsv.CSVWriter; import com.opencsv.bean.BeanToCsv; import com.opencsv.bean.HeaderColumnNameTranslateMappingStrategy; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class CustomBean { private String name; private String surname; public CustomBean(String n, String s) { this.name = n; this.surname = s; } public void setName