Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

reading and writing files in Mac OS X

807588Jun 19 2009 — edited Jun 19 2009
Hello, I am "kind of" experienced with Java (read a few books, and took one course in highschool, and I fool around with it from time to time).

All of this however was on Windows XP, and all from the command line. Because I now have a Macbook Pro, I wish to start programming java on Mac OSX naturally. I've gotten over the shock and awe of using Xcode (I had never use a "package" before with multiple components), but I have come across a problem. I referenced one of my Java books on how to read from a .txt file (my intended program needs a database), but I've been trying for a few hours now, and I just can't seem to get it to work at all.

I want to read the entire file and save it as a String. I don't know if there is a different procedure on OSX than Windows, but here is what I am using:
import java.io.*;
etc. etc.
public String readPlease() {
	String str = "";
	try {
		FileReader file = new FileReader("database.txt");
		BufferedReader buff = new BufferedReader(file);
		str = buff.readLine();
		buff.close();
		return str;
	} catch (IOException e) {
		return e.toString();
	}
}
And it is returning:
java.io.FileNotFoundException: database.txt (No such file or directory)
The .java file and the .txt file are in the same folder (src) and I've tried it while its in "resources" and "bin" (where the .class files are).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2009
Added on Jun 19 2009
5 comments
1,162 views