简体   繁体   English

如何将JTextArea的完整数据保存到csv文件的单个单元格中

[英]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. 我将JTextArea数据保存到csv文件中,但是应用程序未将整个数据保存在单个单元格中。

for example: In JTextArea i added data as below 例如:在JTextArea中,我添加了如下数据

apple
mango
banana
guava

In .csv file it is saving in four rows instead of single row. 在.csv文件中,它保存为四行而不是单行。

below is my code how iam saving the data. 下面是我的代码如何iam保存数据。

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: 为什么不用逗号替换JTextArea的换行符,以便给您一个CSV行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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