I got error of ArrayIndexOutOfBounds Exception in following code.
Please help me to how to solve the error.I also used String tokenizer class.
import java.io.*;
import java.lang.*;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.StringTokenizer;
public class CSV{
public static void main(String[] args) {
// TODO Auto-generated method stub
String fileName="C:/Users/JAL/Desktop/dataset.csv";
try {
BufferedReader br = new BufferedReader( new FileReader(fileName));
String strLine = null;
StringTokenizer st = null;
int lineNumber = 0, tokenNumber = 0;
int row = 0;
int col = 0;
String [][] numbers = new String[100][100];
while( (fileName = br.readLine()) != null)
{
//lineNumber++;
//break comma separated line using ","
st = new StringTokenizer(fileName, ",");
while(st.hasMoreTokens())
{
//display csv values
tokenNumber++;
numbers[row][col]=st.nextToken();
col++;
//System.out.println("Line # " + lineNumber +
//", Token # " + tokenNumber
//+ ", Token : "+ st.nextToken());
}
row++;
//reset token number
tokenNumber = 0;
}
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}