Problem reading a text file into a two-dimensional character array
Hi everyone,
I'm having an issue with a project. We have to create a Maze class, where the maze is a two dimensional character array filled with characters read in from a text file using Scanner. For example, one of the files looks like this:
V V N N N
N V V N N
N N V V V
N N V N V
I have tried several different things, but none have given me the proper output. Here is what I tried to use most recently:
public void fillMaze() throws IOException
{
Scanner sc = new Scanner(System.in);
String fileName;
String line;
String[] temp;
count = 1;
System.out.println("Enter the name of the file you'd like to fill the Maze with.");
fileName = sc.nextLine();
Scanner scFile = new Scanner(new FileReader(fileName));
while(scFile.hasNext())
{
line = scFile.nextLine();
temp = new String[count];
temp[count-1] = line;
count++;
}
}
Any help or feedback anyone can give me would be much appreciated.
Thanks!