package com.testing;
import java.io.BufferedReader;
import java.io.FileReader;
public class CsvParser {
public static void main(String[] args) {
String csvFile = "D:/code-home/SentimentAnalysis/test_data/Sentiment Analysis Dataset.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = "\t";
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String []tweet = line.split(cvsSplitBy);
System.out.println(tweet[1]);
System.out.println(tweet[3]);
}
}
The program's purpose is to parse the CSV format. I have used bufferRead method.
When I go to compile the program, it works fine. When I run the program, I get an error,
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at com.testing.CsvParser.main(CsvParser.java:34)
lineyou are attempting to split? Usually CSV files use a comma separator, not\t(CSV = Comma Separated Values).// use comma as separator