I need to take a text file and initialize a 2d array from the text in that file. Each line in the text file has 20 characters. 5 lines.
So far all I have is
int totalRow = 5;
int totalColumn = 20
char[][] myArray = new char[totalRow][totalColumn];
File file = new File("test.txt");
Scanner scanner = new Scanner(file);
int row = 0;
int column = 0;
while (scanner.hasNextLine()){
while (scanner.hasNext()){
myArray[row][column] = scanner.next();
column++;
}
row++;
}
The problem I am having at the moment is that I get error: string cannot be converted to char
Additionally I am not very familiar with the scanner class, so if hasNextLine, and hasNext are not appropriate for what I am trying to achieve, please let me know.