I've got a file that contains something like this:
Hello;my name;is Marco
I want;some cheese
Hi
this;is;a;test
As you can see I have some words which are separated by a ;
. Number of elements in the rows are not fixed, so I need a dynamic way of reading each row. I tried using String split
method, this way for each row that I'm reading:
String supp = "";
while((supp = read.split(";")[i]) != null){
i++;
}
System.out.println("Number of elements: " + i);
But of course it's not working (ArrayIndexOutOfBoundsException
).
How can I read the whole file dynamically?