本文整理汇总了Java中org.apache.commons.csv.CSVFormat.withRecordSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java CSVFormat.withRecordSeparator方法的具体用法?Java CSVFormat.withRecordSeparator怎么用?Java CSVFormat.withRecordSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.csv.CSVFormat
的用法示例。
在下文中一共展示了CSVFormat.withRecordSeparator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActiveFormat
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
CSVFormat getActiveFormat() {
CSVFormat answer = format;
if (commentMarkerDisabled) {
answer = answer.withCommentMarker(null); // null disables the comment marker
} else if (commentMarker != null) {
answer = answer.withCommentMarker(commentMarker);
}
if (delimiter != null) {
answer = answer.withDelimiter(delimiter);
}
if (escapeDisabled) {
answer = answer.withEscape(null); // null disables the escape
} else if (escape != null) {
answer = answer.withEscape(escape);
}
if (headerDisabled) {
answer = answer.withHeader((String[]) null); // null disables the header
} else if (header != null) {
answer = answer.withHeader(header);
}
if (allowMissingColumnNames != null) {
answer = answer.withAllowMissingColumnNames(allowMissingColumnNames);
}
if (ignoreEmptyLines != null) {
answer = answer.withIgnoreEmptyLines(ignoreEmptyLines);
}
if (ignoreSurroundingSpaces != null) {
answer = answer.withIgnoreSurroundingSpaces(ignoreSurroundingSpaces);
}
if (nullStringDisabled) {
answer = answer.withNullString(null); // null disables the null string replacement
} else if (nullString != null) {
answer = answer.withNullString(nullString);
}
if (quoteDisabled) {
answer = answer.withQuote(null); // null disables quotes
} else if (quote != null) {
answer = answer.withQuote(quote);
}
if (quoteMode != null) {
answer = answer.withQuoteMode(quoteMode);
}
if (recordSeparatorDisabled) {
answer = answer.withRecordSeparator(null); // null disables the record separator
} else if (recordSeparator != null) {
answer = answer.withRecordSeparator(recordSeparator);
}
if (skipHeaderRecord != null) {
answer = answer.withSkipHeaderRecord(skipHeaderRecord);
}
return answer;
}
示例2: getParser
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
/**
* Ritorna il parser costruito secondo i parametri passati per leggere il
* file
*
* @param fileName nome del file da parsare
* @param delimiter delimitatore delle colonne
* @param quoting carattere di quoting
* @param escape carattere di escaping
* @param lineSeparator separatore di righe
* @param charset charset UTF o ISO
* @return Parser per il file CSV
*/
public static CSVParser getParser(String fileName, String delimiter, String quoting, String escape, String lineSeparator, String charset) {
File csvData = new File(fileName);
if (!csvData.exists()) {
int pos = fileName.replace('\\', '/').lastIndexOf('/');
if (pos != -1) {
fileName = fileName.substring(pos + 1);
csvData = new File("./" + fileName);
}
}
if (csvData.exists()) {
try {
CSVFormat format;
if (delimiter != null && delimiter.length() > 0) {
if (delimiter.length() == 2 && delimiter.startsWith("\\")) {
if ("\\t".equalsIgnoreCase(delimiter)) {
format = CSVFormat.newFormat('\t');
} else {
format = CSVFormat.newFormat(delimiter.charAt(0));
}
} else {
format = CSVFormat.newFormat(delimiter.charAt(0));
}
} else {
format = CSVFormat.newFormat(CSVFormat.DEFAULT.getDelimiter());
}
if (quoting != null && quoting.length() > 0) {
format = format.withQuote(quoting.charAt(0));
}
if (escape != null && escape.length() > 0) {
format = format.withEscape(escape.charAt(0));
}
if (lineSeparator != null && lineSeparator.length() > 0) {
format = format.withRecordSeparator(lineSeparator);
}
return CSVParser.parse(csvData, Charset.forName(charset), format);
} catch (Exception e) {
LogGui.printException(e);
}
}
return null;
}