[英]how to read a specific row from csv file using CsvReader in java
I am using CsvReader library and want to read a specific row from a csv file in java. 我正在使用CsvReader库,并希望从java中的csv文件中读取特定的行。 Sample csv :
示例csv:
**Name**, **Address**, **Email-Id**
student, studentaddress, student@email.com
student2, student2address, student2@email.com
employee, employeeaddres1, employee@email.com
I want to read the row where name is 'student2'. 我想读取名称为'student2'的行。 Could you please provide a solution?
你能提供解决方案吗?
Thanks in advance. 提前致谢。
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. 由于行具有不同的字节大小,并且由于CSV格式不包含索引,因此您无法直接对一行进行随机访问 。
So you must read all precedent rows and simply skip them until you're at the desired one. 因此,您必须阅读所有先行行,然后跳过它们,直到您达到所需的行。
I have some experience with this type of operation , just try this API http://opencsv.sourceforge.net/ 我对这种类型的操作有一些经验,只需尝试这个API http://opencsv.sourceforge.net/
we have an option to skip the first n
records 我们可以跳过前
n
条记录
eg: CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\\t', '\\'', 2);
例如:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\\t', '\\'', 2);
this shows it will skip the first 2 records. 这表明它将跳过前2个记录。 look through it
透过它看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.