Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CSVReader from opencsv.CSVReader for a String

Tags:

java

csv

I would like to use the CSVReader in opencsv to read a string of comma separated values. I have used this reader with a multipart file in the past wherein the following would be done: CSVReader reader = new CSVReader(new InputStreamReader(fileName.getInputStream());

This is fine for a multipart file however I cannot find a solution for this if I simply want to pass in a string e.g. one line of CSV's.

like image 345
TKPhillyBurb Avatar asked Aug 30 '26 00:08

TKPhillyBurb


1 Answers

You can use java.io.StringReader. Example:

final String inputString = "value1,value2,value3";

try (CSVReader reader = new CSVReader(new StringReader(inputString))) {
    // Your code here
}
like image 125
Eien Avatar answered Sep 01 '26 13:09

Eien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!