I need to read a text file in a 2d array.
The only problem I ran into is the width of the array with a maximum size of 9 columns. I do not know how many lines there will be.
Some rows will have, for example, 6 columns, and some will have 9.
here is a small section of my CSV file:
1908,Souths,Easts,Souths,Cumberland,Y,14,12,4000 1909,Souths,Balmain,Souths,Wests,N 1910,Newtown,Souths,Newtown,Wests,Y,4,4,14000 1911,Easts,Glebe,Glebe,Balmain,Y,11,8,20000 1912,Easts,Glebe,Easts,Wests,N 1913,Easts,Newtown,Easts,Wests,N
and here is my code so far
import java.io.*; import java.util.*; public class ass2 { public static void main(String[] args) throws IOException { readData(); } public static void readData() throws IOException{ BufferedReader dataBR = new BufferedReader(new FileReader(new File("nrldata.txt"))); String line = ""; ArrayList<String[]> dataArr = new ArrayList<String[]>();
The error I am getting is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6 at ass2.readData(ass2.java:23) at ass2.main(ass2.java:7)
Someone can help: '(
Thanks!