javaを使用してcsvに空白行を挿入したい。私は次のコードを書きました:
CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator("\n").withEscape('\\');
FileWriter fileWriter = new FileWriter(csvFile);
CSVPrinter csvFilePrinter = new CSVPrinter(fileWriter,csvFileFormat);
csvFilePrinter.printRecord("data1");
csvFilePrinter.printRecord("\n");
csvFilePrinter.printRecord("data2");
この生成されたCSVをnotepad ++で開くと、2つの空白行が表示されます。
data1
"
"
data2
単一の空白行を取得するにはどうすればよいですか?
試してみてください、自動的に行をエスケープします。追加のエスケープ文字は必要ありません。csvFilePrinter.printRecord("");
csvFilePrinter.println();
printRecord
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加