Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relative Addressing for .txt Files

 
David Dickinson
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'd like to remove the use of absolute addressing in my program and use a relative path to my .txt file. At the moment I have a statement like so:


But I wan't this to change to reflect the file existing locally within my Eclipse Workspace files.

I've tried altering the path to simply "Garage.txt" which didn't work and i've tried "GarageAssignment\Garage.txt" but this didn't work either.

The file appears within Eclipse's Package Explorer next to my classes so its' recognising its existence.

Thanks
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use a relative path name, then the only question is relative to what? The answer is, relative to where the process was launched. Given the following test code:



If you invoke the JVM from the directory that contains this package as

then you will see the file "test.txt" created in the dirctory just above, assuming that you aren't calling this from the root of the file system.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Philip says, you need to find what Eclipse considered the "current working directory" when it launches your program. I'm not familiar with Eclipse, but in NetBeans, you can set the current working directory under Tools | Options. You should look in the Eclipse help files or browse its options in order to find what this setting is and how you can modify it.

HTH

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic