I'm trying to load file, which looks like this:
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
to 2d array, which is in class sudokuboard.
The function, which i use for this is following:
@Override
public SudokuBoard read() throws DaoException {
SudokuBoard board = new SudokuBoard();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
while (in.ready() == true) {
for (int row = 0; row < 9; row++) {
for (int column = 0; column < 9; column++) {
board.setDigit(row, column, in.read());
//System.out.print(in.read() + ", ");
}
in.read(); // this is important
System.out.println("");
}
}
} catch (IOException e) {
throw new DaoException(DaoException.IO_EXCEPTION, e);
}
return board;
}
What i have after reading this file is:
0 0 0 6 115 113 0 126 0
0 0 0 4 115 113 0 126 0
0 0 0 2 115 113 0 126 0
0 0 0 3 115 113 0 126 0
0 0 0 8 115 113 0 126 0
0 0 0 5 115 113 0 126 0
0 0 0 1 115 113 0 126 0
0 0 0 9 120 120 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
Anybody knows where the problem is ?
Thanks for help !
BufferedReader.read()? docs.oracle.com/javase/7/docs/api/java/io/… And you can read aboutready()method while you are there.