Click here to Skip to main content
15,907,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm new to java and I'm currently making a maze from a text file. Here is example code of how to create the maze, but my problem is actually getting the program to read the text file, this message comes up:
"Error :java.io.FileNotFoundException: sample_maze2.txt (The system cannot find the file specified)"

Here is the code:

Java
public class JavaTest {
	public static void main(String[] args) {
		TextIO.readFile("sample_maze2.txt");
		// sample_maze2.txt has a line with two numbers on it saying how many rows and
		// how many columns of characters there are in the rest of the file.
		// All calls to TextIO.get methods read now read from sample_maze2.txt.
		int rows = TextIO.getInt();  // this is the number of rows in the file (maze)
		int cols = TextIO.getlnInt();  // this is the number of columns in the file (maze)
		char[][] array = new char[6][12];
		// Each line of sample_maze2.txt contains cols number of characters
		// and there are rows number of lines
		for (int i=0; i < rows; i++) {
			for (int j=0; j < cols; j++) {
				array[i][j] = TextIO.getChar();
			}
			TextIO.getln();
		}
		TextIO.readStandardInput(); // This closes the file
		TextIO.putln("Display the maze using 'maze' characters:");
		// In the maze project, whenever you read a '0' you display a wall character
		// whenever you read a '1' you display a path character
		// whenever you read a '2' you display an entrance character
		// whenever you read a '3' you display an exit character
		for (int i=0; i < rows; i++) {
			for (int j=0; j < cols; j++) {
				if (array[i][j]=='0') TextIO.put('*');
				if (array[i][j]=='1') TextIO.put(' ');
				if (array[i][j]=='2') TextIO.put('E');
				if (array[i][j]=='3') TextIO.put('X');
			}
			TextIO.putln();
		}
		
		
	}
}


Quick help would be great, it's been a problem for me, and if it's solved I should be able to be well on my way, thanks!
Posted
Updated 13-May-11 6:23am
v4
Comments
Fabio V Silva 13-May-11 12:23pm    
Updated formatting.

Provide the full path to your file.

/Fredrik
 
Share this answer
 
Put 'sample_maze2.txt' in your root folder. Currently the file being searched/looked for by the code is not on the path specified. Correct it. You can use absolute path or relative path as per your choice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900