org.apache.commons.csv

Class CSVUtils


public class CSVUtils
extends java.lang.Object

Utility methods for dealing with CSV files

Field Summary

private static String[][]
EMPTY_DOUBLE_STRING_ARRAY
private static String[]
EMPTY_STRING_ARRAY

Constructor Summary

CSVUtils()
CSVUtils instances should NOT be constructed in standard programming.

Method Summary

static String[][]
parse(String s)
Parses the given String according to the default CSVStrategy.
static String[]
parseLine(String s)
Parses the first line only according to the default CSVStrategy.
static String
printLine(String[] values)
Converts an array of string values into a single CSV line.

Field Details

EMPTY_DOUBLE_STRING_ARRAY

private static final String[][] EMPTY_DOUBLE_STRING_ARRAY

EMPTY_STRING_ARRAY

private static final String[] EMPTY_STRING_ARRAY

Constructor Details

CSVUtils

public CSVUtils()
CSVUtils instances should NOT be constructed in standard programming.

This constructor is public to permit tools that require a JavaBean instance to operate.

Method Details

parse

public static String[][] parse(String s)
            throws IOException
Parameters:
s - CSV String to be parsed.
Returns:
parsed String matrix (which is never null)

parseLine

public static String[] parseLine(String s)
            throws IOException
Parses the first line only according to the default CSVStrategy. Parsing empty string will be handled as valid records containing zero elements, so the following property holds: parseLine("").length == 0.
Parameters:
s - CSV String to be parsed.
Returns:
parsed String vector (which is never null)

printLine

public static String printLine(String[] values)
Converts an array of string values into a single CSV line. All null values are converted to the string "null", all strings equal to "null" will additionally get quotes around.
Parameters:
values - the value array
Returns:
the CSV string, will be an empty string if the length of the value array is 0