0

Like the question says, how do I do this.

5 Answers 5

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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

3 Comments

This isn't a complete implementation. In CSV it's possible to escape using quotes. The provided example doesn't support this functionality.
@Tarlog I did't say it was a complete implementation. It's just an example of how to use StringTokenizer in the OP's question context. StringTokenizer is one of the easier ways to go if you don't want to use any third party modules/libraries.
Yes, I understand: it's easy, but it doesn't work in this case. But it's easy... Oh yes: easy. But it doesn't work... Who cares, if it's easy?
0

Apache Wink provides CsvReader and CsvWriter utilities.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.