Questions tagged [opencsv]

opencsv is a simple csv (comma-separated values) parser library for Java

What is opencsv ?

opencsv is a simple csv (comma-separated values) parser library for Java. It was developed in response to a lack of csv parsers with commercial-friendly licenses.

Where can I get it?

Source and binaries are available from Sourceforge. You can check out the javadocs online.

What features does opencsv support?

opencsv supports all the basic csv-type things you're likely to want to do:

  • Arbitrary numbers of values per line
  • Ignoring commas in quoted elements
  • Handling quoted entries with embedded carriage returns (ie entries that span multiple lines)
  • Configurable separator and quote characters (or use sensible defaults)
  • Read all the entries at once, or use an Iterator style model
  • Creating csv files from String[] (ie. automatic escaping of embedded quote chars)
1008 questions
0
votes
1 answer

How do I add an item to a String array of type List?

In my code, I am reading in a text file using CSVReader and putting all that into a String array of type list: CSVReader reader = new CSVReader(new FileReader("addTest.txt"), ','); List myEntries = reader.readAll(); reader.close(); I'm…
juiceb0xk
  • 949
  • 3
  • 19
  • 46
0
votes
3 answers

How would I extract a specific row in a .CSV file?

The goal of my code is to ask for a user input, the user specifies this input and my code is to search and find out which row the user input is located. Once located, I will then have code to extract that row into something (string array?) so I can…
juiceb0xk
  • 949
  • 3
  • 19
  • 46
0
votes
2 answers

Object[] cannot be converted to String[]

The goal of my code is to replace a certain text value within my .CSV file with the user input of a text field. My .CSV file has values delimited by commas: hey,hi. If I'm just wanting to replace 'hey' then I would gather the input from the text…
juiceb0xk
  • 949
  • 3
  • 19
  • 46
0
votes
0 answers

Auto detect column types in OpenCSV

I'm reading a file with OpenCSV this way (in Scala): val reader = new CSVReader(new FileReader("somefile.txt")) for (row <- reader.readAll) { println("col(0): " + row(0) + " col(1)" + row(1) ) } Since the file was provided by a user, I don't…
ps0604
  • 1,227
  • 23
  • 133
  • 330
0
votes
0 answers

OpenCSV - readAll function gives error with special characters

I am trying to read a CSV file using the OpenCSV library. My data is in the following format in the CSV. "No", "Name", "Address", "Date" "1", "Harry", "River's Drive", "02/11/2016 00:00:01" "2", "Tom", "Cover's Park", "03/11/2016 00:00:01" It can…
Aman Mohammed
  • 2,878
  • 5
  • 25
  • 39
0
votes
1 answer

Writing java object into .csv

I have the java class below: class DeviceUser{ private String d1; @CsvBind private Long u1; @CsvBind private Long lt; @CsvBind private DeviceUser ref; //getters and setters } I want to write the data, stored in the DeviceUser object, into a .csv…
sachin10
  • 31
  • 1
  • 10
0
votes
1 answer

Android Handler timing delayed when app runs in background

in my app I am writing data to a CSV file every second. I am using a Handler with postAtTime for this purpose. This works fine as long as the screen is on. The data gets written almost exactly every second. For example the data looks like this…
Luigi04
  • 437
  • 5
  • 14
0
votes
0 answers

JAVA : opencsv reading CSV cell randomly

I am trying to convert CSV into JSON and using OpenCSV and trying to add attributes of JSON from CSV header. For that, I am extracting first row from CSV into separate array and then processing the remaining CSV and adding it to JSON. But it's not…
roger_that
  • 9,493
  • 18
  • 66
  • 102
0
votes
3 answers

csvWriter behave differently on unix machine (tomcat sever) for huge file (size 5000 KB) and it creates empty file,Same Code work fine at windows,WHY?

I am writing csv file with the help of csvWriter (Java) but while executing code on Unix Box with huge records (Around 9000) it creates empty file. When i try to execute same code at local( Eclipse ) at windows it works fine for same huge file.…
0
votes
0 answers

java.lang.ClassNotFoundException: com.opencsv.CSVParser

I start using hadoop to run my code on aws. However, I got the error when using hadoop jar command: Error: java.lang.ClassNotFoundException: com.opencsv.CSVParser at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at…
user3162707
  • 721
  • 1
  • 7
  • 7
0
votes
1 answer

I am getting null for the one of the column value after extraction. What's wrong with the following program?

I am getting null for one of the selected column with IterableCSVToBean DTO Classe: public class MessageFileExtractHeader implements Serializable { private static final long serialVersionUID = -3052197544136826142L; …
Sam
  • 1
  • 1
0
votes
2 answers

Why and how does CSVReader take multiple lines as single line when it discovers \" in a field?

I am using au.com.bytecode.opencsv.CSVReader to read A csv file and print all the records one by one. The code is behaving strange. It's printing a group of lines together as a single line. Then again it's printing next set of lines correctly. Link…
Satej Koli
  • 79
  • 2
  • 15
0
votes
1 answer

Ignoring CSV values with openCSV + Storing int values from CSV file in separate two-dimensional array elements

First part to my question is, if I have a CSV file with 4 numbers on one line separated by a comma, how do I ignore the first two values using openCSV? Now, consider the following array: int[][] parsedData = new int [10][10]; and the following line…
rst-2cv
  • 1,130
  • 1
  • 15
  • 31
0
votes
2 answers

OpenCsv | SQL | Writes only the header and not the table content

I am trying to execute an SQL statement through Java and write the results to a .csv file. I am using OJDBC.jar (v7) to connect to Oracle 11g DB and OPENCSV.jar (v3.8) for creating and writing into the excel. Table result is printing very well. I am…
Shreyas SG
  • 368
  • 3
  • 6
  • 21
0
votes
1 answer

Using a for loop to read certain files using read.csv() but it's only returning "'file' must be a character string or connection"

Here is the data I am working with. https://d396qusza40orc.cloudfront.net/rprog%2Fdata%2Fspecdata.zip I'm trying to create a function called pollutantmean that will load selected files, aggregate (rbind) the columns, and return a mean of a certain…