@CodeReview(reviewer="Kevin R. Dixon",date="2006-07-18",changesNeeded=false,comments="Minor spacing changes to while statement. Otherwise, looks fine.") @CodeReview(reviewer="Kevin R. Dixon",date="2008-02-08",changesNeeded=true,comments="This class should make the comma a parameter (in the splitCommas() method) so that it can be used on all character-delimited parsing schemes.",response=@CodeReviewResponse(respondent="Justin Basilico",date="2008-02-18",moreChangesNeeded=false,comments="Added the split() method")) public class CSVUtility extends java.lang.Object
CSVUtility
class implements some utility functions for
dealing with comma-separated value (CSV) file types.Constructor and Description |
---|
CSVUtility() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
nextNonEmptyLine(java.io.BufferedReader r)
Returns the next non-empty line from the given BufferedReader as an
array of the CSV entries.
|
static java.lang.String[] |
nextNonEmptyLine(java.io.BufferedReader r,
char delimiter)
Returns the next non-empty line from the given BufferedReader as an
array of the CSV entries.
|
static java.util.LinkedList<java.lang.String[]> |
readFile(java.lang.String fileName)
Reads a CSV file into a list of arrays of string values.
|
static java.util.LinkedList<java.lang.String[]> |
readFile(java.lang.String fileName,
char delimiter)
Reads a CSV file into a list of arrays of string values.
|
static java.lang.String[] |
split(java.lang.String line,
char c)
Splits the given line into the array of character-separated values.
|
static java.lang.String[] |
splitCommas(java.lang.String line)
Splits the given line into the array of comma-separated values.
|
public static java.lang.String[] nextNonEmptyLine(java.io.BufferedReader r) throws java.io.IOException
r
- The BufferedReader to read from.java.io.IOException
- If there is an exception in reading from the
BufferedReader.public static java.lang.String[] nextNonEmptyLine(java.io.BufferedReader r, char delimiter) throws java.io.IOException
r
- The BufferedReader to read from.delimiter
- Delimiter to use.java.io.IOException
- If there is an exception in reading from the
BufferedReader.public static java.lang.String[] splitCommas(java.lang.String line)
line
- The line to split on the commas.public static java.lang.String[] split(java.lang.String line, char c)
line
- The line to split on the given character.c
- The character to use to split the line.public static java.util.LinkedList<java.lang.String[]> readFile(java.lang.String fileName) throws java.io.IOException
fileName
- The file to read in.java.io.IOException
- If there is an error reading the file.public static java.util.LinkedList<java.lang.String[]> readFile(java.lang.String fileName, char delimiter) throws java.io.IOException
fileName
- The file to read in.delimiter
- Delimiter to use.java.io.IOException
- If there is an error reading the file.