Solved

NEWBIE: Relative to what?

Posted on 2006-06-16
12
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 16920638
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
ID: 16920675
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:Mayank S
ID: 16920729
No, java.exe can also be located anywhere in the PATH environment variable, and can be called from any directory therefore.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 16920787
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
ID: 16920814
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:Mayank S
ID: 16920816
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
 

Author Comment

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

Expert Comment

by:Mayank S
ID: 16920831
>> 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:
Mayank S earned 125 total points
ID: 16920832
>> it "relative to C:\MyDir"?

Correct.
0
 

Author Comment

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

Author Comment

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

Expert Comment

by:Mayank S
ID: 16920867
You still have doubts about this?
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaFX TableView not displaying correctly 3 109
jboss 7.1 start up error 1 64
Chrome and Firefox Java 5 69
collection output issue 9 66
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 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