Results 1 to 3 of 3
Thread: Finding Text Files
- 05-13-2011, 04:37 PM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
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.
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)"?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(); } } }
Quick help would be great, if I solved this, I'd be well on my way!
- 05-13-2011, 06:52 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
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!");
- 05-13-2011, 07:34 PM #3
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
finding regex patterns in text file
By jessie in forum New To JavaReplies: 4Last Post: 11-08-2010, 08:42 PM -
Finding Jar files in a class file
By bnrkcdc in forum Jobs DiscussionReplies: 4Last Post: 09-08-2010, 01:46 PM -
help...! about reading a text file and finding their average
By nemesis in forum New To JavaReplies: 20Last Post: 10-20-2008, 11:02 AM -
Behaving text files like binary files
By Farzaneh in forum New To JavaReplies: 2Last Post: 08-27-2008, 03:20 PM -
Text and image files within jar files
By erhart in forum Advanced JavaReplies: 8Last Post: 01-19-2008, 04:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks