4/17/19

CSV File parsing in Java


CSV is a simple file format used to store tabular data, such as a spreadsheet or database. Files in the CSVformat can be imported to and exported from programs that store data in tables, such as Microsoft Excel or OpenOffice Calc. CSV stands for "comma-separated values".

CSV - Comma Suppurated Values

 CSV File Download Resorce of this project file.   - CSVFile.txt


CSV File parsing Java Code...


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

public class CSVParseBasic {

    public static void main(String[] args) {

        CSVParseBasic csv = new CSVParseBasic();
        csv.run();

    }

    public void run() {

        String csvFile = "CSVFile.txt";
        BufferedReader br = null;
        String line = "";
        String csvSplitBy = ",";

        try {

            br=new BufferedReader(new FileReader(csvFile));

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

                String[] country = line.split(csvSplitBy);
                System.out.println("Country[code= "+country[4]+ " , name= "+country[5]+"] ");
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("Completed!");

    }

}

No comments:

Post a Comment

About

Hi, I'm Najathi.
I've started entrepreneurial company, Twin Brothers.Inc.
One is self-funded & the other is venture backed. I also send a weekly. where I share relevent, curated links.

Every Week I Publish a short post on writing, publishing, or content of IT Related

Contact Form

Name

Email *

Message *