• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

NEWBIE: Relative to what?

Dear Experts,

When I specify a relative path to a file, such as:

FileInputStream fis = new FileInputStream ( "filename.ext" )

is the path relative to where java.exe is located, or relative to where my class is located?

Thanks,
BrianMc1958
0
BrianMc1958
Asked:
BrianMc1958
  • 7
  • 5
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
Relative to the directory where you are running it from:

C:\MyDir> java someClass

The file will be looked for in C:\MyDir

someClass can be anywhere in the class-path
0
 
BrianMc1958Author Commented:
I take that to mean it's relative to where java.exe is, not from where the class is.  Right?  (That seems to be what I'm seeing here...)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
No, java.exe can also be located anywhere in the PATH environment variable, and can be called from any directory therefore.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Mayank SAssociate Director - Product EngineeringCommented:
The PATH environment variable contains directory-paths whose files (generally executables) can be called from anywhere. If I am calling java.exe from C:\MyDir, then java.exe need not be present there. The OS will first look in the current directory to locate it. If it is not found, it will look into the directories in the PATH variable and search for java.exe there.
0
 
BrianMc1958Author Commented:
I'm sorry.  I'm still confused.  So is the answer to my question is "Neither.  The 'relative' means 'relative to your current working directory'"?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
So you can have java.exe present in "C:\program files\Java\jdk1.5.0_06\bin" and as long as that directory is in the PATH, you can call java.exe from anywhere, say C:\MyDir
0
 
BrianMc1958Author Commented:
In other words, it "relative to C:\MyDir"?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> The 'relative' means 'relative to your current working directory'"

Yes. The location of java.exe, the location of the class that is being run and the location of the directory where you are running the class from can all be different.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> it "relative to C:\MyDir"?

Correct.
0
 
BrianMc1958Author Commented:
As a side note, all of our last four posts "crossed in the mail", yet still make perfect sense.  
0
 
BrianMc1958Author Commented:
Make that last six posts.  I'd better quit.  This is getting creepy.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You still have doubts about this?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now