Solved

NEWBIE: Relative to what?

Posted on 2006-06-16
12
267 Views
Last Modified: 2010-03-31
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
Comment
Question by:BrianMc1958
  • 7
  • 5
12 Comments
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
 

Author Comment

by:BrianMc1958
Comment Utility
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
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
No, java.exe can also be located anywhere in the PATH environment variable, and can be called from any directory therefore.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
 

Author Comment

by:BrianMc1958
Comment Utility
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
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:BrianMc1958
Comment Utility
In other words, it "relative to C:\MyDir"?
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> 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
 
LVL 30

Accepted Solution

by:
mayankeagle earned 125 total points
Comment Utility
>> it "relative to C:\MyDir"?

Correct.
0
 

Author Comment

by:BrianMc1958
Comment Utility
As a side note, all of our last four posts "crossed in the mail", yet still make perfect sense.  
0
 

Author Comment

by:BrianMc1958
Comment Utility
Make that last six posts.  I'd better quit.  This is getting creepy.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
You still have doubts about this?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now