1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| import java.io.*;
import java.util.Scanner;
public class Maze {
static int rows = 10;
static int columns = 10;
static char maze [][] = new char [rows][columns];
public static void main(String[] args)throws IOException {
String filename;
boolean valid = false;
boolean approved = false;
boolean opened = false;
String OK;
String ok;
char choice;
Scanner input = new Scanner(System.in);
//prompt user for name of file to be loaded
do{
do{
System.out.println("\nPlease enter name of file containing the maze: ");
filename = input.nextLine();
try
{
BufferedReader in = new BufferedReader(new FileReader(filename));
for (int a=0; a<maze.length; a++)
{
for (int b=0; b<maze[0].length; b++)
{
maze[a][b] = (char)in.read();
System.out.print(maze[a][b]);
}
}
System.out.println();
opened = true;
in.close();
}
catch (FileNotFoundException e){System.out.println("File Not Found !");}
catch (IOException e){System.out.println("I/O Exception !");}
}while(!opened); |
Partager