如何使用opencsv将整数值写入csv文件

时间:2014-10-06 11:17:09

标签: java opencsv

这是我编写csv文件的代码

CSVWriter writer = new CSVWriter(new FileWriter("test.csv",false));
String [] details = new String[]{"00000002","0","0","0","0","type_detils","01","1","-1","0.0","0.0","CST"};
writer.writeNext(details);

我想在csv中写这个值格式:

00000002,0,0,0,0,"type_detils",01,1,-1,0.0,0.0,"CST"

但是当我查看文件时,它是这样的:

"00000002","0","0","0","0","type_detils","01","1","-1","0.0","0.0","CST"

如何在使用opencsv?

的文件写入期间将字符串值更改为整数

1 个答案:

答案 0 :(得分:2)

您可以尝试这样的3参数构造函数(link):

CSVWriter writer = new CSVWriter(new FileWriter("test.csv",false),',','\0');

使用'\ 0'是空字符。或者,如果CSVWriter接受它,则可能传递null。