what is the easiest way of looking for a file in your current directory (ie, the directory the Java program is executing from) ? On a related subject (as this was my forst guess at how to achive the above), if you specify a file without any directory info as being say "myfile.txt", where does Java look for it?
Example output: C:\My Java Stuff\Sample Programs\CurrentDir Program From that, you could create a new file reader using the string containing the user's directory and append a slash (for windows) and then the filename.
<Edit>: By the way, I just checked, Java looks for a file in the current directory, so rather than using the code above you could simply use a file reader and pass the name of the file relative to the current directory. [ February 08, 2004: Message edited by: Donny Nadolny ]
- Donny Nadolny<br />The pen is mightier than the sword, and considerably easier to write with.
That's odd, I tried it as well and it didnt find the file. location of the .class I am excuting C:\java\projects\myproject\ Image i = Toolkit.getDefaultToolkit().getImage("MyLogo.jpg"); <--- not found Image i = Toolkit.getDefaultToolkit().getImage("C:\\java\\projects\\myproject\\MyLogo.jpg"); <---- found
I'll have to do some experimenting I guess :/ [ February 08, 2004: Message edited by: Maarten Vergouwen ]
Amusing. I am using NetBeans IDE, and apparently when you run an application, no matter where its source/class files are located, it takes the netbeans\bin directory as its current dir... if I put the pic in there, it loads.
Edit: if I run the program outside of the IDE, it works. So it wasnt a problem to begin with, heh. Thanks Donny! [ February 08, 2004: Message edited by: Maarten Vergouwen ]