This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Scala and the fly likes Question regarding, Scala IO and reading a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "Question regarding, Scala IO and reading a file" Watch "Question regarding, Scala IO and reading a file" New topic
Author

Question regarding, Scala IO and reading a file

Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Given the following code



..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()!
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

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.


Mohamed Sanaulla | My Blog
Samuel Cox
Ranch Hand

Joined: Nov 16, 2004
Posts: 96

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.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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)

[CODE]
Exception in thread "main" java.lang.ExceptionInInitializerError
#######.main.FileProcessorUtilityTest.main(FileProcessorUtility.scala)
Caused by: java.io.FileNotFoundException: test.txt (No such file or directory)


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").

Your scala-file is generated?


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question regarding, Scala IO and reading a file
 
Similar Threads
problem using s:action tag
New to Struts, where did I go wrong?
Struts2 newbee - Problem when using form tag
NullPointerException at StringTokenizer
Difference between <forrward> in <action-mappings> and <forward> in <global-forwards>