Java BufferedReader Read loadCsvFile(String fileWithPath, String delimiter)

Here you can find the source of loadCsvFile(String fileWithPath, String delimiter)

Description

Read a CSV file and put each line into the list.

License

Open Source License

Parameter

Parameter Description
fileWithPath path to the CSV file
delimiter , usually comma

Return

list of arrays and array of strings

Declaration

public static List<String[]> loadCsvFile(String fileWithPath, String delimiter) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import java.util.List;
import java.util.Vector;

public class Main {
    /**/*www.  j  a v a2s .co  m*/
     * Read a CSV file and put each line into the list. Each item have a arrays of strings (for each column)
     * 
     * @param fileWithPath path to the CSV file
     * @param delimiter , usually comma
     * @return list of arrays and array of strings
     */
    public static List<String[]> loadCsvFile(String fileWithPath, String delimiter) {
        // read CSV file
        Vector<String[]> list = new Vector<String[]>();
        if (delimiter == null || delimiter.equals("")) {
            delimiter = ",";
        }
        BufferedReader reader = null;
        String readString;
        try {
            // open file
            reader = new BufferedReader(new FileReader(new File(fileWithPath)));
            while ((readString = reader.readLine()) != null) {
                list.add(readString.split(delimiter));
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
}

Related

  1. loadConfFile(String filename, String key)
  2. loadConfig(File conf)
  3. loadConfigProps(String configFile)
  4. loadContents(File file)
  5. loadCredentials(File credentials)
  6. loadDataURLs(File f, Pattern p)
  7. loadDict(InputStream io, boolean case_sensitive)
  8. loadEnrichmentHits(File file)
  9. loadIgnorList()