Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-14-2007, 11:15 PM   PM User | #1
newbiecoder
New to the CF scene

 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
newbiecoder is an unknown quantity at this point
Howto get a relative path to a file

Hi there,

I'm trying to read a configuration file called "user.ini" into my application.
When i try to do this from within netbeans everything is fine.

After building it however it goes wrong.

The application will eventually be called from within the windows scheduler to run daily. therefore i would like to execute it with just a single command like

java -classpath "d:\java apps\mahler\dist\jftpmahler.jar" -jar "d:\java apps\mahler\dist\jftpmahler.jar"

when i do execute that from the project directory ../dist (where also the .ini file resides) everything is fine.

when i do execute the same command from any other location however i get a FileNotFoundException error for the "user.ini" file.

now im sure i could make a batch file so i could run it from the application directory. However this is not wanted, therefore i would like to get a relative path to the user.ini file.

i have read several posts on different forums on how to get a relative path and use that to make an absolute path to the file but i dont seem to get that working. but that is basically what i want, to get a relative path to the file so, no matter where the application is, it will alway be able to find the ini file.


sofar i use this code to open the ini file:

ReadIni ini = new ReadIni("user.ini");

public ReadIni(String IniFileName)
{

inifile = IniFileName;
try
{
p.load(new FileInputStream (inifile));
}
catch(Exception e)
{ //..... }
}


well im hoping for a solution, but in any case thanks for reading.
newbiecoder is offline   Reply With Quote
Old 04-15-2007, 11:28 AM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
put it inside the jar file and use

Code:
p.load(this.getClass().getResourceAsStream(inifile));
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 04-15-2007, 11:38 AM   PM User | #3
newbiecoder
New to the CF scene

 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
newbiecoder is an unknown quantity at this point
Thanks shyam,

I tried it out and it works fine. this was exactly what i was looking for.
newbiecoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:47 AM.


Advertisement
Log in to turn off these ads.