Saran
Saran

Reputation: 443

How to read a CSV file to array in Java

Like the question says, how do I do this.

Upvotes: 0

Views: 1810

Answers (5)

Matt
Matt

Reputation: 772

Use OpenCSV, it will be quick and easy

CSVReader reader = new CSVReader(new FileReader("C:\\Documents\\file.csv"));
List<String[]> csvValues = reader.readAll();

This code sample will give you a List with String arrays inside of it.

Upvotes: 2

Sudhanshu Umalkar
Sudhanshu Umalkar

Reputation: 4202

Use split() method on the read line to get the array. The method takes in the regular expression for splitting.

Upvotes: 0

Tarlog
Tarlog

Reputation: 10154

Apache Wink provides CsvReader and CsvWriter utilities.

Upvotes: 0

Lou
Lou

Reputation: 1955

Try opencsv. Seems like it'll do the job.

Upvotes: 4

Bala R
Bala R

Reputation: 108947

You could use StringTokenizer class. Here's an example.

Upvotes: 0

Related Questions