It can be archived to closet to your requirement by using different CSV Formats. Check Below which one suits you.
Available Formats are Following
CSVFormat DEFAULT
Description: Standard comma separated format, as per RFC4180 specification but allowing empty lines.
CSVFormat RFC4180
Description: Comma separated format as defined by RFC4180 specification
Ref: https://www.rfc-editor.org/rfc/rfc4180
CSVFormat EXCEL
Description: Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is locale dependent, it might be necessary to customize this format to accommodate to your regional settings.
CSVFormat TDF
Description: Tab-delimited format.
CSVFormat MYSQL
Description: Default MySQL format used by the SELECT INTO OUTFILE and code LOAD DATA INFILE operations. This is a tab-delimited format with a LF character as the line separator. Values are not quoted and special characters are escaped with ''.
Ref: http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Also, apart from the standard CSVFormat
There are many methods you can use as per your requirement.
- withAllowMissingColumnNames() - Sets the missing column names behavior of the format to true
- withAllowMissingColumnNames(boolean allowMissingColumnNames) - Sets the missing column names behavior of the format.
- withCommentMarker(char commentMarker) - Sets the comment start marker of the format to the specified character.
- withCommentMarker(Character commentMarker) -Sets the comment start marker of the format to the specified character.
- withDelimiter(char delimiter) - Sets the delimiter of the format to the specified character.
- withEscape(char escape) - Sets the escape character of the format to the specified character.
- withEscape(Character escape) -Sets the escape character of the format to the specified character.
- withHeader(ResultSet resultSet) -Sets the header of the format.
- withHeader(ResultSetMetaData metaData) -Sets the header of the format.
- withHeader(String... header) -Sets the header of the format.
- withHeaderComments(Object... headerComments) -Sets the header comments of the format.
- withIgnoreEmptyLines() -Sets the empty line skipping behavior of the format to true.
- withIgnoreEmptyLines(boolean ignoreEmptyLines) - Sets the empty line skipping behavior of the format.
- withIgnoreSurroundingSpaces() - Sets the trimming behavior of the format to true.
- withIgnoreSurroundingSpaces(boolean ignoreSurroundingSpaces) - Sets the trimming behavior of the format.
- withNullString(String nullString) - Performs conversions to and from null for strings on input and output.
- withQuote(char quoteChar) - Sets the quoteChar of the format to the specified character.
- withQuote(Character quoteChar) - Sets the quoteChar of the format to the specified character.
- withQuoteMode(QuoteMode quoteModePolicy) -Sets the output quote policy of the format to the specified value.
- withRecordSeparator(char recordSeparator) - Sets the record separator of the format to the specified character.
- withRecordSeparator(String recordSeparator) - Sets the record separator of the format to the specified String.