Here you can find the source of importCsv(File file)
Parameter | Description |
---|---|
file | points to the CSV file |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
IOException | an exception |
public static List<List<String>> importCsv(File file) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { /**// w ww . j a va2s .c o m * Imports a CSV file. * * @param file points to the CSV file * @return List<List<String>> are the rows and columns of the CSV file * @throws FileNotFoundException * @throws IOException */ public static List<List<String>> importCsv(File file) throws FileNotFoundException, IOException { List<List<String>> rows = new ArrayList<List<String>>(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { String line; while ((line = br.readLine()) != null) { rows.add(Arrays.asList(line.split(","))); } } return rows; } }