Results 1 to 3 of 3
  1. #1
    EggoH is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default Finding Text Files

    Hi, I'm new to the forums.

    I joined as I have a problem with a text file. I'm just testing on an example code, but everytime I try and run the java project it says it can not find the file.


    Java 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();
    		}
    		
    		
    	}
    }
    The sample_maze2.txt file is in the same file as the java project I'm making, any reason why I always get "Error :java.io.FileNotFoundException: sample_maze2.txt (The system cannot find the file specified)"?

    Quick help would be great, if I solved this, I'd be well on my way!

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    The file should be found if it's in the project root directory. An easy way to find out where that is, is to create a file in your code and see where it gets put, e.g:
    Java Code:
    TextIO.writeFile("file_test.txt");
    TextIO.put("foo!");

  3. #3
    EggoH is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    Thank you for your quick reply, I have managed to find the textfile now, for some reason the folder it was in, was not acceptable.
    It's now solved!

Similar Threads

  1. finding regex patterns in text file
    By jessie in forum New To Java
    Replies: 4
    Last Post: 11-08-2010, 08:42 PM
  2. Finding Jar files in a class file
    By bnrkcdc in forum Jobs Discussion
    Replies: 4
    Last Post: 09-08-2010, 01:46 PM
  3. Replies: 20
    Last Post: 10-20-2008, 11:02 AM
  4. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  5. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 04:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •