CSVFormat.RFC4180 忽略 .csv 文件中的引用值
CSVFormat.RFC4180 ignores quoted values in .csv file
我有 .csv
个包含引用值的文件
Gender,ParentIncome,IQ,ParentEncouragement,CollegePlans
"Male",53900,118,"Encouraged","Plans to attend"
"Female",24900,87,"Not Encouraged","Does not plan to attend"
"Female",65800,93,"Not Encouraged","Does not plan to attend"
使用以下代码读取此文件(使用 IntelliJ 并在调试器中观察值),returns 个值不带引号。
@Override
public CsvConnectorService read(String fullFileName, String outputAddress, int intervalMs, boolean repeat,
Handler<AsyncResult<Void>> result) {
CSVFormat format = CSVFormat.RFC4180.withHeader().withIgnoreEmptyLines().withQuote('"');
Subscription subscription = createCsvObservable(fullFileName, format, intervalMs, repeat)
.subscribeOn(Schedulers.io())
.subscribe(record ->
eventBus.publish(outputAddress, convertRecordToJson(record)));
subscriptions.add(subscription);
result.handle(Future.succeededFuture());
return this;
}
阅读 .withQuote('"');
或不阅读,都没有区别。
引号 "
是表示带引号字段的默认字符,显式设置它没有任何区别。
你想得到原引文字符吗?在这种情况下,请尝试将引号设置为文本中未出现的字符,例如 .withQuote('[=11=]');
我有 .csv
个包含引用值的文件
Gender,ParentIncome,IQ,ParentEncouragement,CollegePlans
"Male",53900,118,"Encouraged","Plans to attend"
"Female",24900,87,"Not Encouraged","Does not plan to attend"
"Female",65800,93,"Not Encouraged","Does not plan to attend"
使用以下代码读取此文件(使用 IntelliJ 并在调试器中观察值),returns 个值不带引号。
@Override
public CsvConnectorService read(String fullFileName, String outputAddress, int intervalMs, boolean repeat,
Handler<AsyncResult<Void>> result) {
CSVFormat format = CSVFormat.RFC4180.withHeader().withIgnoreEmptyLines().withQuote('"');
Subscription subscription = createCsvObservable(fullFileName, format, intervalMs, repeat)
.subscribeOn(Schedulers.io())
.subscribe(record ->
eventBus.publish(outputAddress, convertRecordToJson(record)));
subscriptions.add(subscription);
result.handle(Future.succeededFuture());
return this;
}
阅读 .withQuote('"');
或不阅读,都没有区别。
引号 "
是表示带引号字段的默认字符,显式设置它没有任何区别。
你想得到原引文字符吗?在这种情况下,请尝试将引号设置为文本中未出现的字符,例如 .withQuote('[=11=]');