This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Relative File() path? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Relative File() path?" Watch "Relative File() path?" New topic
Author

Relative File() path?

Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Hey JavaGurus!

A quick and easy question for those of you who feel at home with the File object.

When I use an absolute file path everything works just as expected:


But what I need is a relative file path.
When I try to implement this using the following code:


It doesnt work at all.
Why?
What is it that Im missing?

Thanks in advance and have a great summer!

Kind regards
[ July 16, 2007: Message edited by: Dominic Steng�rd ]

Dominic Steng�rd<br />Sun Certified Java 2 Programmer
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

The path will be relative to the current working directory, the current directory when the process was launched. You're probably expecting something else. Try calling getAbsolutePath() on your File object to see how your path is being interpreted.


[Jess in Action][AskingGoodQuestions]
Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Thank you Ernest!

You were so right ... calling getAbsolutePath() on the file object gave me a totally different relative path than I had expected.
My code runs just fine now.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Relative File() path?
 
Similar Threads
Need your help about a File Quesion.(scjp03-Q90)
specify relative path in File constructor
Relative Addressing for .txt Files
Writting a String to a file
session null