I have a text file that contains lines, with words separated by commas. I am trying to create an array inside of another array so i can call specific words from the text file. Right now I can save each line of the text file into an array, but I don't know how to call a specific word in a line.
TEXT FILE
Hat, dog, cat, mouse
Cow, animal, small, big, heavy
Right, left, up, down ,behind
Bike, soccer, football, tennis, table-tennis
CODE
animals = new Scanner(new File("appendixA.txt"));
// code for number of lines start
File file =new File("appendixA.txt");
if(file.exists()) {
FileReader fr = new FileReader(file);
LineNumberReader lnr = new LineNumberReader(fr);
int linenumber = 0;
while (lnr.readLine() != null) {
linenumber++;
}
lnr.close();
// code for number of lines end
String animal[] = new String[linenumber];
for (int i = 0; i < linenumber; i++) {
String line = animals.nextLine();
animal[i] = line;
for (int j = 0; j < animal[i].split(",").length; j++) {
String animalzzz[] = animal[i].split(",");
}
}
}