This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
..and given that "test.txt" is in the same folder/package/location as the generated .scala file. I recieve the following error: (I have hashed out the package names as they are private company ones)
...however, if I paste the full path to the location of "test.txt" the application works. This is certainly not practical, by any means. I am using Eclipse, could it be an IDE issue, or should I be able to avoid providing the entire path to a file if its in the root location??
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
I dont know if its better to use an absolute or relative path for the files. But I think using an absolute path for the file should be better. Or using some file chooser UI would also be better.
I'm pretty sure your problem does not lie with Scala. To test this, run Scala's REPL and try to use Source.fromFile on files in the directory from which you started the REPL. I did this and the file loaded fine using relative paths.
If you don't know what the REPL is, you should read up on it. This is a very nice feature of Scala and many other languages.
Anyhow, I'm not sure how you are using Eclipse, but I think you need "test.txt" in the directory that serves as the base when running your application.
Stephen Davies wrote:
..and given that "test.txt" is in the same folder/package/location as the generated .scala file. I recieve the following error: (I have hashed out the package names as they are private company ones)
The location of the scala file, as well as the location of the class-File, is of no interest at all.
Think about cp, ls, less and so on. You nearly never switch to /usr/bin, to invoke those commands/programs. They are shell-builtins? Take xpdf, oowriter, eog, gimp, ...
Your current position is of interest, and the position of the file in question ("test.txt"). In the shell, the first thing is easy to control: pwd, and often shown by the prompt.
On the desktop, inside the IDE, your position is nearly invisible. Eclipse has some settings in the 'run as ...' - Dialog. Normally that's the bin or classes-dir. While the test.txt, if it resides where the source is, probably is ("../src/test.txt").