Article View: borland.public.jbuilder.java.language
Article #7404Re: Locating an INI file
From: Rich Wilkman
Date: Thu, 21 Jun 2001 16:16
Date: Thu, 21 Jun 2001 16:16
40 lines
2250 bytes
2250 bytes
Mio:
For an X-Platform, Java happy approach, try something like:
Properties props = new Properties();
URL u = MyClassThatNeedsProperties.class.getResource("foo.properties");
props.load(u.openStream());
There's a try-catch missing, of course. You can fiddle with the
resource name and make it point to a directory under the location of the
class, etc. if you like.
Basically, the "java way" is to store and load resources relative to the
class that needs them. So, if you have a class com.foo.Bar.class that
needs bar.properties and use the above method, then bar.properties needs
to be stored in the same location as Bar.class on the classpath.
-Rich
-Rich
Mio Nino Marquez wrote:
>
> Java newbie here. :)
>
> I've written a bunch of class under a package (say MyLib). One class needs
> to read an INI file for some configuration settings. Initially, I have hard
> coded the location of the file. But now, I don't want it to be hard coded.
>
> So I guess my question is, how do I know the location of the class /
> package? Code snippets would definitely be helpful.
>
> PS: In Delphi I can use the ExtractFilePath(application.exename) to get the
> location of the exe file. i'm looking for something similar in java.
>
> Thanks in advance!
>
> Mio Nino Marquez
Technical Details
Message-ID:
<3B321DFB.FDB5BBC2@formlessvoid.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnewsReferences:
<3b317205_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,52be12fbe909d3e9 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-06-21 09:36:22 PST Message-ID: <3B321DFB.FDB5BBC2@formlessvoid.com> Date: Thu, 21 Jun 2001 09:16:59 -0700 From: Rich Wilkman <richw@formlessvoid.com> X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: Locating an INI file References: <3b317205_1@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 208.236.69.60 X-Trace: dnews 993140217 208.236.69.60 (21 Jun 2001 09:16:57 -0700) Lines: 40 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews