0

hi all
i want to read CSV file how can i do that

please help me with a bit of code

Thanks
Kirti

Edited by kirtichopra: it is CSV file and not CVS

4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by pooja.ui7
0

By searching this forum you will find plenty of examples on how to read files. Look for the classes:
BufferedReader
Scanner

0

By searching this forum you will find plenty of examples on how to read files. Look for the classes:
BufferedReader
Scanner

Thanks i will search this

0
//Code for reading data from CSV file

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.StringTokenizer;

public class CSVReader {
    public static void main(String args[]) throws IOException {
        String filename = "samples.csv";
        String linedata;
        FileInputStream fileInputStream = new FileInputStream(filename);
        DataInputStream dataInputStream = new DataInputStream(fileInputStream);
        while ((linedata = dataInputStream.readLine()) != null) {
            StringTokenizer stringTokenizer = new StringTokenizer(linedata, ",");
            while (stringTokenizer.hasMoreElements()) {
                String token = stringTokenizer.nextToken();
                System.out.print(token + ", ");
            }
            System.out.println();
        }
    }
}

SNIP

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.