Since we know CSV files content has each line separated using \r\n
, then we can get each line easily. Code like:
scanner.useDelimiter("\r\n");
while(scanner.hasNext()){
scanner.next();
}
But how if a field of CSV file has "\r\n" inside, then this code doesn't work! Like CSV here:
Row1: "abc\r\nabc","abc","abc"
Row2: "efg", "efg", "efg"
Row3: "hjk", "hjk"
I would like using scanner to read in as:
"abc\r\nabc","abc","abc"
"efg", "efg", "efg"
"hjk", "hjk"
but if just using \r\n
, it turns out would be:
“abc
abc","abc","abc"
"efg", "efg", "efg"
"hjk", "hjk"
What change should I do? How to modify scanner.useDelimiter("\r\n")
to make the pattern workable?