[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

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