I have been trying to convert a file to a String [] [] for several days now, but I still have an error. I don't know how to proceed.
String[][] lecture_tab;
public void readLines() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("lvl1.txt"));
int i = 0;
while (i < 15) {
for (String line; (line = br.readLine()) != null; ) {
System.out.println(line);
this.lecture_tab[i] = line;
i += 1;
}
}
System.out.println(lecture_tab);
}
The text file looks like this :
###################
###################
###################
###################
###################
###################
###################
###################
###################
###################
###################
###################
###################
###################
###################
/!\ UPDATE /!\ : After listening to your advice i finally got to do what i wanted to do. Well almost, when I try to display my matrix, there is only the first line displayed, the 14 other lines are empty ...
public void readLines() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("lvl1.txt"));
for (int i = 0; i < lecture_tab.length; i++) {
for (String line; (line = br.readLine()) != null;) {
for(int j = 0; j < 19; j++) {
this.lecture_tab[i][j] = line.charAt(j);
}
}
}
for (int i = 0; i < this.lecture_tab.length; i++) {
for (int j = 0; j < this.lecture_tab[i].length; j++) {
System.out.print(this.lecture_tab[i][j]);
}
System.out.println();
}
}
The output :
###################