I want to put my string in (.csv) file. but if string contains commas, it split and moves to next cell.
String str=resultSet.getString();
Since you're writing a CSV file with comma delimiter and your text happens to have a comma in it as well, you need to wrap your text within double quotes :
String str = "\"hello, world\"";
So, if the string you want to write is str
:
String str = ...;
...
str = "\"" + str + "\"";// do this before put str content in your csv file
This should work.
Double quote the column value if there's an embedded comma:
Ex:
column1_data, column2_data, "column3_data, new_data", column4_data
here it will consider column3_data, new_data
as value in column3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.