List of utility methods to do CSV File Parse
List | csvLineParse(String line, char delimiter) csv Line Parse List<String> strings = new ArrayList<String>(); boolean inQuotes = false; StringBuilder field = new StringBuilder(); for (int walk = 0; walk < line.length(); walk++) { char ch = line.charAt(walk); if (ch == delimiter) { if (inQuotes) { field.append(ch); ... |
String[] | csvSplitLine(String line, char fieldSeparator) Basic CSV line splitting that takes quotes into account. LinkedList<String> fields = new LinkedList<String>(); boolean inQuote = false; String field = ""; for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == '\"') { if (inQuote && i + 1 != line.length() && line.charAt(i + 1) == '\"') { field += '\"'; i++; ... |
List | parse(final String csvString) Splits the csv string. return parse(csvString, ",", true); |
List
| parseCsv(InputStream csvInput) CSV content parser. return parseCsv(csvInput, DEFAULT_CSV_SEPARATOR);
|
List | parseCsv(InputStream fileStream) parse Csv BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream)); List<Integer[]> allCodes = new ArrayList<Integer[]>(); String line; while ((line = reader.readLine()) != null) allCodes.add(parseCsvLine(line)); return allCodes; |
List | parseCSV(String csv) Parses a CSV string into a list of strings, removing spaces and empty strings String[] vals = csv.split(","); List<String> strs = new ArrayList<String>(); for (String val : vals) { String v = val.trim(); if (v.length() > 0) strs.add(v); return strs; ... |
String[] | parseCSV(String csv) parse CSV List<String> vals = new ArrayList<String>(); boolean quoted = false; StringBuffer val = new StringBuffer(); for (int i = 0; i < csv.length(); i++) { char c = csv.charAt(i); if (c == '\"') { if (quoted) { quoted = false; ... |
String[][] | parseCSV(String csvString) Parses a given multi-line CSV-formated string to a String matrix. if (isEmptyString(csvString)) { return new String[0][]; char c = '0'; boolean valueStarted = false; boolean stringValueStarted = false; char[] csvArray = csvString.toCharArray(); Vector lines = new Vector(); ... |
String[] | parseCSV(String data, char... ch) Method to parse character separated values, generic version of comma separated values Supports escape Character List<String> values = new ArrayList<String>(); char seperator = ((null == ch) || (ch.length < 1) || (ch[0] == NULL)) ? ',' : ch[0]; char escapeChar = ((null == ch) || (ch.length < 2) || (ch[1] == NULL)) ? '\\' : ch[1]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length(); ++i) { char c = data.charAt(i); if (c == seperator) { values.add(sb.toString()); ... |
ArrayList | parseCsvFile(String filename, String csvSplitBy, boolean skipHeader) parse Csv File ArrayList<Float> parsedCsvFile = new ArrayList<>(); parsedCsvFile.add(-1.0f); try { BufferedReader br = new BufferedReader(new FileReader(filename)); try { if (skipHeader) br.readLine(); String line; ... |