How to read data from CSV using Java PLM Developer

CSV (Comma Separated Values) is a file format having the values separated with a comma. Let us see how to read a CSV using a Java Program.  Reading the file and processing from BufferReader is one of the ways to do it.

Read Data From CSV in Java

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class ReadDataFromCSVFile {

             public static final String PATH = "C:\\Input\\Data.csv";

             public static void main(String[] args) throws FileNotFoundException {
              try {

                 BufferedReader reader = new BufferedReader(new FileReader(PATH));

                 String line = null;

                 while ((line = reader.readLine()) != null) {

                   String sData[] = line.split(",");

                     for (int i = 0; i < sData.length; i++) {

                          System.out.println("data:::::" + sData[i]);

                     }
                 }
                    // close reader
                      reader.close();
                   } catch (Exception e) {
                        e.printStackTrace();
                    }
              }
 }

Post a Comment

0 Comments