测试文件制作迷宫 [英] Test Files making a Maze
本文介绍了测试文件制作迷宫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java的新手,目前正在用文本文件做一个迷宫.这是如何创建迷宫的示例代码,但是我的问题实际上是让程序读取文本文件,出现此消息:
"Error :java.io.FileNotFoundException: sample_maze2.txt (The system cannot find the file specified)"
这是代码:
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:
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!
推荐答案
提供文件的完整路径.
/Fredrik
Provide the full path to your file.
/Fredrik
在您的根文件夹中放入"sample_maze2.txt".当前,代码正在搜索/查找的文件不在指定的路径上.改正它.您可以根据需要使用绝对路径或相对路径.
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.
这篇关于测试文件制作迷宫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文