2014-10-06 63 views
2

一個整數值寫入csv文件這是我寫一個CSV文件中的代碼如何使用opencsv

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將字符串值更改爲整數?

+0

如果可能的話,您可以在生成CSV格式的同時更改CSV格式,我的意思是您可以使用設置忽略數字的雙引號.. – 2014-10-06 11:20:23

+0

您是否檢查過'CSVWriter'(它來自哪個包?)正在工作? – Smutje 2014-10-06 11:29:08

回答

1

你可以嘗試3 PARAM構造(link)是這樣的:

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

使用 '\ 0' 是空字符。或者,如果CSVWriter接受它,可以傳遞null。