I am reading in a text file with the format of a 16x16 sudoku puzzle.
For Example:
F7B-E-A-1--6---D -91AF-0-85D7E4-C 05-69C---B-EA-3- -C-E-2-B--A-7860 E05---2F-7---1C- -4-8-DC--E-593-- -29---1-D--A-04- D67-A-98----B-F- 9B-D-130C8--F5A- 8F4569EA7D--CB-- 6A---745BFE-12D9 7--1DBFC-A-04--E 5-F9C-61240D-7E- A--7-F-DE-580-2- --0-5E7-F63C--14 CE640-----7B5D9F
I'm attempting to put the values into a 2D char array, but when encountering the end of a line 3 spaces seem to be included. I've tried using various ways like BufferedReader and FileInputStream to no avail. The text files must be in that format as my professor will be testing with his own values using that format.
My code for getting the file into an ArrayList:
private static ArrayList readFile(File filename)
{
ArrayList records = new ArrayList();
try
{
FileInputStream stream = new FileInputStream(filename);
char current;
while(stream.available() > 0)
{
current = (char)stream.read();
records.add(current);
}
stream.close();
return records;
}
catch (Exception e)
{
System.err.format("Exception occurred trying to read '%s'.", filename);
return null;
}
}
I then use an iterator to start assigning values to the 2D array. When printing out the grid it appears fine, but when checking individual values, like grid[1][1], it's not right because of the spacing it throws in.
Is there a way to read in char by char, but avoid the 3 spaces it puts in to represent the new line?