There are some easy ways ...
If you get the whole file as one big line (say using apache commons-io), you can do this:
String csv = rawString.replaceAll("(?ms)$.*?^", ", ");
Or, if you have a file like List<String>:
List<String> lines;
String csv = lines.stream().collect(Collectors.joining(", "));
source
share