简体   繁体   中英

How to save complete data of JTextArea in to single cell of csv file

Iam saving JTextArea data in to csv file, but application is not saving the entire data in single cell.

for example: In JTextArea i added data as below

apple
mango
banana
guava

In .csv file it is saving in four rows instead of single row.

below is my code how iam saving the data.

String address ;
address = textArea.getText();
writer.append(address);
writer.append(',');

Can anyone suggest how to fix the issue?

Thanks

Why not replace the newline characters of the JTextArea with the commas to give you a single CSV row:

writer.append(address.replace("\n", ","));

Output:

apple,mango,banana,guava
writer.append(address.replace("\n", "-"));

Use character other than ",". If not, data will be placed in consecutive cell of the same row

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM