i have GB of size csv file , i'am able to read this but when splitting it to an array then printing cause ArrayIndexOutOfBoundsException this is my program
FileInputStream inputStream = null;
Scanner sc = null;
try {
inputStream = new FileInputStream("file.csv");
sc = new Scanner(inputStream, "UTF-8");
int j=0;
while (sc.hasNextLine()) {
String[] data=new String[4];
String line=sc.nextLine();
data=line.split(",");
System.out.println(data[0]+" "+data[1]+" "+data[2]+" "+data[3]);
}
if (sc.ioException() != null) {
throw sc.ioException();
}
}
catch (IOException ex) {
Logger.getLogger(TestPrintingAllLine.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (inputStream != null) {
inputStream.close();
}
if (sc != null) {
sc.close();
}
}
After executing 536 lines then, it caused ->
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 at enterdatatosql.TestPrintingAllLine.main(TestPrintingAllLine.java:45) Java Result: 1.
45th line is-> System.out.println(data[0]+" "+data[1]+" "+data[2]+" "+data[3]);