Reputation: 171
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.
Upvotes: 6
Views: 5866
Reputation: 1167
You can use java.io.StringReader
. Example:
final String inputString = "value1,value2,value3";
try (CSVReader reader = new CSVReader(new StringReader(inputString))) {
// Your code here
}
Upvotes: 15