public final class CsvFiles extends Object
| Modifier and Type | Method and Description |
|---|---|
static List<String[]> |
getCsvDataArray(Reader csvReader,
boolean headerPresent)
Returns a
List<String[]> that contains all rows of the CSV file. |
static List<String[]> |
getCsvDataArray(String fileName,
boolean headerPresent)
Returns a
List<String[]> that contains all rows of the CSV file. |
static List<String> |
getCsvDataByColumn(String fileName,
int column,
boolean headerPresent)
Returns a
List<String> representing a single 0-indexed column. |
static List<Map<String,String>> |
getCsvDataListMap(String fileName,
boolean headerPresent)
Returns a
List<Map<String, String>> that contains all rows with
a field mapping defined by the header. |
static Map<String,String> |
getCsvDataMap(String fileName,
boolean headerPresent)
Returns a
Map<String, String> mapping of the first column to the
second column. |
static Map<String,String> |
getCsvDataMap(String fileName,
int key,
int value,
boolean headerPresent)
Returns a
Map<String, String> mapping of the column designated by
key to the column designated by value. |
static Map<String,String[]> |
getCsvDataMapArray(String fileName,
boolean headerPresent)
Returns a
Map<String, String[]> mapping of the first column to an
array of the rest of the columns. |
static void |
writeCsv(List<String[]> csvData,
String fileName)
Writes the CSV data located in
csvData to the file located at
fileName. |
public static Map<String,String> getCsvDataMap(String fileName, int key, int value, boolean headerPresent) throws IOException
Map<String, String> mapping of the column designated by
key to the column designated by value. This method also
ignores all columns other than the columns specified by key and
value.fileName - the CSV file to loadkey - the 0-indexed column number to map to the key of the returned
data mapvalue - the column number to map to the value of the returned data
mapheaderPresent - true if the fist line is the headerMap<String, String> mapping of the columns specified by
key and valueIOException - if there was an error while reading the fileIllegalArgumentException - if CSV file does not have the
columns specified by key or valuepublic static Map<String,String> getCsvDataMap(String fileName, boolean headerPresent) throws IOException
Map<String, String> mapping of the first column to the
second column. This method also ignores all columns other than the first
two.fileName - the CSV file to loadheaderPresent - true if the fist line is the headerMap<String, String> mapping of the first to the second
columnIOException - if there was an exception reading the fileIllegalArgumentException - if CSV file has fewer than two
columnspublic static Map<String,String[]> getCsvDataMapArray(String fileName, boolean headerPresent) throws IOException
Map<String, String[]> mapping of the first column to an
array of the rest of the columns.fileName - the CSV file to loadheaderPresent - true if the fist line is the headerMap<String, String[]> mapping of the first column to an
array of the rest of the columnsIllegalArgumentException - if there is fewer than 2 columns in
the CSVIOException - if there was an exception reading the filepublic static List<Map<String,String>> getCsvDataListMap(String fileName, boolean headerPresent) throws IOException
List<Map<String, String>> that contains all rows with
a field mapping defined by the header. If no header is present,
then each field is the 0-indexed column number.fileName - the CSV file to loadheaderPresent - true if the first line is the headerList<Map<String, String>> that contains all rows with
with a field mapping defined by the header if present.IOException - if there was an exception reading the filepublic static List<String> getCsvDataByColumn(String fileName, int column, boolean headerPresent) throws IOException
List<String> representing a single 0-indexed column.fileName - the CSV file to loadcolumn - the 0-indexed column to returnheaderPresent - true if the first line is the headerList<String> representing a single columnIOException - if there was an exception reading the fileIllegalArgumentException - if the column index does not exist in
the CSVpublic static List<String[]> getCsvDataArray(String fileName, boolean headerPresent) throws IOException
List<String[]> that contains all rows of the CSV file.
The header will be removed, if present.fileName - the CSV file to loadheaderPresent - true if the first line is the headerList<String[]> that contains all rows of the CSV fileIOException - if there was an exception reading the filepublic static List<String[]> getCsvDataArray(Reader csvReader, boolean headerPresent) throws IOException
List<String[]> that contains all rows of the CSV file.
The header will be removed, if present.csvReader - reader used to read the csvheaderPresent - true if the first line is the headerList<String[]> that contains all rows of the CSV fileIOException - if there was an exception reading the filepublic static void writeCsv(List<String[]> csvData, String fileName) throws IOException
csvData to the file located at
fileName.csvData - the CSV data including the headerfileName - the file to write the CSV data toIOException - if there was an error writing to the fileIllegalArgumentException - if csvData == nullCopyright © 2015. All Rights Reserved.