开发者

How to import multiline csv files?

I got a file in this format.

"abc";"def";"ghi
asdasd
asdasd
asd
asd
aas
d
"

Now i want to import it w开发者_运维知识库ith Java. Does anyone know a library that support this kind of import?


Perhaps JavaCSV.


Commons CSV's Excel format successfully parses multiline CSVs:

Reader in = new FileReader("path/to/file.csv");
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in);
for (CSVRecord record : records) {
    String lastName = record.get("Last Name");
    String firstName = record.get("First Name");
}


If you want to do is just import that kind of file, I think any of the 3 or 4 main Java CSV libraries should do the job.

But you can take a look at this post if you want to have an overview on the many features and differences between SuperCSV, OpenCSV and JavaCSV. I already used JavaCSV to write the kind of file you want to read and it was perfect.

Note : not sure but I heard that only SuperCSV is still maintained


There are a number of CSV utilities out there, and the best I've come across is OsterMiller. The API is good, it can handle very large datasets gracefully, as well as being aware of the odd CSV that MS Excel generates for some kinds of data.


There is an additional problem which I didn't realized earlier. I think this is why the libraries don't work.

there are double quotes inside the csv "fields", like that:

one recordset:

"abc";"def";"ghi
asdasd
asdasd
asdasd "asd"
asd
aas
d
"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜