Class CSVReader
java.lang.Object
CSVReader
CSV-file reader help functions.
See: wikipedia.org/wiki/Comma-separated_values#Toward_standardization
- Since:
- 2014-07-16
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Main test function.static String
makeLineFromStrings
(String... list) Make a CSV line from strings (for writing)static int
Parse string to integer, treating dash as zero.static String[][]
Read in a text file.static String[][]
Read in a text file.static String[]
Split one line with proper quote handling.static String[]
splitLineNoQuotes
(String line) Split one line with no quote-handling (for testing)static String
Trim off trailing delimiters of a string.
-
Field Details
-
COMMA
private static char COMMAStandard delimiter for a CSV file (comma). -
QUOTE
private static char QUOTEQuotes used for special field containers.
-
-
Constructor Details
-
CSVReader
public CSVReader()
-
-
Method Details
-
readFile
Read in a text file. Assumes default charset.- Parameters:
filename
- File to read.- Returns:
- Array of split string arrays.
- Throws:
IOException
-
readFile
Read in a text file.- Parameters:
filename
- File to read.charset
- Name of encoding type.- Returns:
- Array of split string arrays.
- Throws:
IOException
-
splitLine
Split one line with proper quote handling.- Parameters:
line
- Line to split.- Returns:
- Array of split strings.
-
trimTrailingDelimit
Trim off trailing delimiters of a string.- Parameters:
s
- String to trim.- Returns:
- Trimmed String.
-
splitLineNoQuotes
Split one line with no quote-handling (for testing)- Parameters:
line
- Line to split.- Returns:
- Array of split Strings.
-
parseInt
Parse string to integer, treating dash as zero.- Parameters:
s
- String to parse.- Returns:
- Parsed integer.
-
makeLineFromStrings
Make a CSV line from strings (for writing)- Parameters:
list
- String list.- Returns:
- Comma-separated string.
-
main
Main test function.
-