Exception in thread "main" org.supercsv.exception.SuperCsvException: The number of columns to be processed (229326) must match the number of CellProcessors (8):
長期的には簡単になるかもしれないので、supercsvを使用してやり直さなければならないかもしれませんが、他の提案も受け付けています。私は単にcsvファイルに書き戻したいのですが、すべてのデータを含むリストがありますが、出力は次のようになります
4350 02/06/2013 3965.21 0.0 0.0 0.0 0.0 0.0,
4698 02/06/2013 498.16 0.0 0.0 0.0 0.0 0.0,
4992 02/06/2013 97.87 87.82 6.05 0.0 0.0 0.0,
4441 02/06/2013 18.8 71.98 11.6 0.0 0.0 -42.5, 54092 02/06/2013 105.11 118.82 6.24 0.0 0.0 0.0,
リスト内の文字列を置き換えることで、必要な出力を得ることができましたが、実行するとハングし、csvに書き戻す方法が原因だと思います。他に何をすべきかわかりませんスーパーcsvを使用せずにcsvに書き戻すよりも。私が得るエラーは
"1805","31/07/2013","-233.4","0.0","0.0","0.0","0.0","0.0"
"8054","31/07/2013","280.45","82.38","52.38","0.0","0.0","-200.0"The number of columns to be processed (1) must match the number of CellProcessors (8):
私のウィータークラスは次のとおりです
package writer;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.supercsv.cellprocessor.FmtDate;
import org.supercsv.cellprocessor.ParseDouble;
import org.supercsv.cellprocessor.ParseInt;
import org.supercsv.cellprocessor.constraint.NotNull;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvListWriter;
import org.supercsv.io.ICsvListWriter;
import org.supercsv.prefs.CsvPreference;
public class RentStatementsWriter {
public ArrayList rData;
private List<String> csvData;
char b = ',';
public RentStatementsWriter(ArrayList rentData) {
rData = rentData;
ICsvListWriter listWriter = null;
try{
listWriter = new CsvListWriter(new FileWriter("rentl.csv"),CsvPreference.STANDARD_PREFERENCE);
CellProcessor[] processors =new CellProcessor[]{
new ParseInt(),
new FmtDate("dd/MM/yyyy"),//
new ParseDouble(),
new ParseDouble(),
new ParseDouble(),
new ParseDouble(),
new ParseDouble(),
new ParseDouble(),
};
final String [] header = new String []{"_num", "End_Date", "bal_val","rval","cval","bf_val","aval","pval"};
System.out.print("to string "+rData.toString().replaceFirst(" ", "\"").replaceAll("\\,"," \\,").replaceAll(" ", "").replaceAll(" ", "\"\\,\"").replaceAll("\"\\,\"\\,", "\"\n\""));
csvData = Arrays.asList(rData.toString().replaceFirst(" ", "\"").replaceAll("\\,"," \\,").replaceAll(" ", "").replaceAll(" ", "\"\\,\"").replaceAll("\"\\,\"\\,", "\"\""));
/*
* replace
* .replaceAll(" ", "\"\\,\"")
*/
listWriter.writeHeader(header);
listWriter.write(csvData, processors);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.print(e+" file unable to write");
} finally {
if(listWriter !=null){
try {
listWriter.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("list writer");
}
}
}
}
String listToCsv(List<String> listOfStrings, char separator) {
StringBuilder sb = new StringBuilder();
// all but last
for(int i = 0; i < listOfStrings.size() - 1 ; i++) {
sb.append("\""+listOfStrings.get(i)+"\"");
sb.append(separator);
}
// last string, no separator
sb.append(listOfStrings.get(listOfStrings.size()-1));
return sb.toString();
}
}
この構文に欠けているもの、またはこのタスクを実行するためのより良い方法はありますか