Reading and Writing files (Java, Mac OSX)
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:
(using the "premade model" with Xcode)
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).
Thank a lot 🙂
MacBook Pro, Mac OS X (10.5.7)