Wednesday 1 April 2020

TableSaw: Create table from csv file

Below statement reads the data from 'sample.csv' file and create a table from it.
Table table = Table.read().csv("sample.csv");

employee.csv
1,Hari Krishna,Gurram
2,Kiran Kumar,Darsi
3,Rama Krishna,Gurram
4,Gopi,Battu
5,Sudheer,Ganji

App.java
package com.sample.app;

import java.io.IOException;

import tech.tablesaw.api.Table;

public class App {

 public static void main(String args[]) throws IOException {
  String csvFilePath = "/Users/krishna/Documents/employee.csv";

  Table table = Table.read().csv(csvFilePath);

  System.out.println(table.print());
 }
}

Output
          employee.csv           
 1  |  Hari Krishna  |  Gurram  |
---------------------------------
 2  |   Kiran Kumar  |   Darsi  |
 3  |  Rama Krishna  |  Gurram  |
 4  |          Gopi  |   Battu  |
 5  |       Sudheer  |   Ganji  |



Previous                                                    Next                                                    Home

No comments:

Post a Comment