How to read CSV File in Java

Here we can learn how to read CSV file comma seprated in java below is the code

--> Use apache API to read CSV or use BufferReader
--> here i have used Buffer Reader


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
 *
 * @author anand
 *
 */
public class ReadCSVFile {

    public static void main(String[] args) {

     
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ","; //Comma seprated

        try {

            br = new BufferedReader(new FileReader("Your_CSV_FILE_NAME"));
            while ((line = br.readLine()) != null) {
                System.out.println("Content \t"+line);

            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }}

Comments

Popular posts from this blog

Converting JSONArray into CSV file in java

Java Design pattern

Map class field to map