I need to make a 2D array out of the 0's and 1's in the file. The file is 25X25 in total so contains 625 characters in all, either 0 or 1.
This is the code I have so far:
import london.*;
public class Picture {
public static void main (String[] arg) {
EasyReader fileInput = new EasyReader("picture.txt");
EasyGraphics g = new EasyGraphics(30,30);
int cols = 30; // How many columns the array should have
int rows = 30; // How many rows the array should have
int[][] array2d = new int[rows][cols];
String strLine;
int xCounter = 0;
// Reading lines from the file using EasyReader
while ((strLine = fileInput.readLine()) != null) // fileInput.readLine() fills the variable strLine with a String value.
{
char[] stringArray= new char[42];
stringArray = strLine.toCharArray();
//display the array
for(int index=0; index < stringArray.length; index++) {
array2d[xCounter][index] = (int) stringArray[index] - 0x30;
}
xCounter++;
}
}
}
The EasyReader is just a class for input that inherits the BufferedReader class and is part of the "london" package. There is 1 error in compilation which says:
Picture.java:15: unreported exception java.io.IOException; must be caught or declared to be thrown
while ((strLine = fileInput.readLine()) != null) // fileInput.readLine() fills the variable strLine with a String value.
^
Please can someone help me, this is driving me mental!
