3

I am using CsvReader library and want to read a specific row from a csv file in java. Sample csv :

**Name**,     **Address**,        **Email-Id**
student,    studentaddress,     [email protected] 
student2,   student2address,    [email protected] 
employee,   employeeaddres1,    [email protected]

I want to read the row where name is 'student2'. Could you please provide a solution?

Thanks in advance.

0

2 Answers 2

5

As rows have different sizes in bytes, and as the CSV format doesn't contain an index, you can't have a random access directly to one row.

So you must read all precedent rows and simply skip them until you're at the desired one.

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

Comments

2

I have some experience with this type of operation , just try this API http://opencsv.sourceforge.net/

we have an option to skip the first n records

eg: CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t', '\'', 2);

this shows it will skip the first 2 records. look through it

Other API's

1 Comment

opencsv isn't an Apache project - you're probably confusing it with commons csv

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.