Hello, this is my first post in this forum. I am a beginner in Java and now I am working on programming Comney's game of life ...
So I started off by writing the initial patterns in text files and now I am trying to read in the text files into two dimensional array
I am using these methods currently but they only read in the text into one dimensional array by using getFileSize(); ... how can I retrieve the two dimensions of the text file? what do i change in these three methods that can help me retrieve the number of columns and rows?
< public static void readFile(String[] words, String fileName)throws IOException { Scanner input = new Scanner(new FileReader(fileName)); int i=0; //index for placement in the array String line; while (input.hasNextLine()) //while there is another line in the file { line=input.nextLine(); //read in the next Line in the file and store it in line words[i]= line; //add the line into the array i++; //advance the index of the array } input.close(); } public static int getFileSize(String fileName)throws IOException { Scanner input = new Scanner(new FileReader(fileName)); int size=0; while (input.hasNextLine()) //while there is another line in the file { size++; //add to the size input.nextLine(); //go to the next line in the file } input.close(); //always close the files when you are done return size; } //pre: //post:displays all of the elements of the array words public static void showArray(String[] words) { for (int i=0; i<words.length; i++) System.out.println(words[i] + " "); System.out.println(); } >