Skip to main content
CSV Logo

CSV file reading and writing in Java using jCSV

CSV Logo


We are going to discuss the jCSV library. The jCSV library is a light-weight library for reading and writing a CSV files in Java. It was released in 2012 but it’s working perfectly. The tutorial will be used Java 8 Lambda expressions for looping. Anyway, you can use Java early version also.


We need to the com.googlecode.jcsv dependency to the project.

for Maven

for Gradle

CSV File writing

Let’s say we have a model, it’s called

Now, we’re ready to implement CSV writer. It’s called

If you carefully look at the code, you can see the java class that name is This class main responsibility is, convert Car object as you want and put data into the String array.

How to run it

Create an Object of Writer class and call the write() method.

You can see the data.csv file is created inside the project directory.

CSV File Reader

We use data.csv for reading also. Need to create a java class that called

Finally, need to implement a helper class for assembling.

How to run it

Entry Filter

Let’s say, you want to filter data while reading. For an example, we need only get cars which are Toyotas.

So that, need to implement a Filter class.

Then, change a CSVReader in the

Now, when you run the application, it will show only the Toyota car.


Related Post

20466total visits,8visits today

Follow by Email