Java CSV File Load importCsv(File file)

Here you can find the source of importCsv(File file)

Description

Imports a CSV file.

License

Open Source License

Parameter

Parameter Description
file points to the CSV file

Exception

Parameter Description
FileNotFoundException an exception
IOException an exception

Return

List> are the rows and columns of the CSV file

Declaration

public static List<List<String>> importCsv(File file) throws FileNotFoundException, IOException 

Method Source Code


//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;
    }
}

Related

  1. importCsv(File file)
  2. importCsv(File file)