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

please help me with a bit of code

Thanks
Kirti

Recommended Answers

All 4 Replies

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

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

//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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.