Here you can find the source of loadCsvFile(String fileWithPath, String delimiter)
Parameter | Description |
---|---|
fileWithPath | path to the CSV file |
delimiter | , usually comma |
public static List<String[]> loadCsvFile(String fileWithPath, String delimiter)
//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; } }