I have a text file that is 32x32 in size. For example first two lines:
11111111111111111111111111111111
11111111111111111111111111111000
...
I want to read and store this file in a 2D array. I have the following java code, but can't exactly figure out how to read the file data. I guess I would need two nested for loops?
public static int[][] readFile(){
BufferedReader br = null;
int[][] matrix = new int[32][32];
try {
String thisLine;
int count = 0;
br = new BufferedReader(new FileReader("C:\\input.txt"));
while ((thisLine = br.readLine()) != null) {
//two nested for loops here? not sure how to actually read the data
count++;
}
return matrix;
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
if (br != null)br.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
return matrix;
}