Simple Code To Read CSV file – JAVA

it’s very simple to read CSV and then get all information by columns this is simple code which will help you with it

try {
BufferedReader br = new BufferedReader(new FileReader("./customer-list.csv"));
  while ((line = br.readLine()) != null) {
   if (!line.isEmpty()) {
    // use comma as separator
    String[] data = line.split(",");
    //data[0] contains first column if you want second one use data[1] and so on
    System.out.println(data[0]);
}
}
 
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Leave a Reply

Your email address will not be published.