Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Properties, canonical way of reading/writing configuration files.

Reply
Thread Tools

Properties, canonical way of reading/writing configuration files.

 
 
lyallex
Guest
Posts: n/a
 
      06-07-2004
On Mon, 07 Jun 2004 14:59:40 +0200, Rogan Dawes <(E-Mail Removed)>
wrote:

....

>
>Please don't take my comments to be knocking Preferences, I think it
>looks great! I'm just pointing out some implementation mistakes that you
>made.
>
>Rogan


Ah, I see, well thanks for that Rogan

Actually the code does exactly what I want it to do.
All I know is that once I have set everything up I can do this

public PropertiesTest() {
prefs = Preferences.userNodeForPackage(this.getClass());
}

public String getPref(String key){
return prefs.get(key, "someDefaultValue");
}

public static void main(String[] args){
System.out.println(newPropertiesTest().getPref("li stenPort"));
}

and still get the output

26358

That is all I wanted.

Rgds
Lyall





 
Reply With Quote
 
 
 
 
Rogan Dawes
Guest
Posts: n/a
 
      06-07-2004
lyallex wrote:

> Actually the code does exactly what I want it to do.
> All I know is that once I have set everything up I can do this
>
> public PropertiesTest() {
> prefs = Preferences.userNodeForPackage(this.getClass());
> }
>
> public String getPref(String key){
> return prefs.get(key, "someDefaultValue");
> }
>
> public static void main(String[] args){
> System.out.println(newPropertiesTest().getPref("li stenPort"));
> }
>
> and still get the output
>
> 26358
>
> That is all I wanted.
>
> Rgds
> Lyall


Sure. All I was saying was that your program was reading the value from
a tree structure under .java, rather than from the .xml file that you
were referring to. As you have shown, you can skip that import step
completely, and still get your values.

Regards,

Rogan
--
Rogan Dawes

*ALL* messages to http://www.velocityreviews.com/forums/(E-Mail Removed) will be dropped, and added
to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
 
Reply With Quote
 
 
 
 
lyallex
Guest
Posts: n/a
 
      06-07-2004
On Mon, 07 Jun 2004 17:26:16 +0200, Rogan Dawes <(E-Mail Removed)>
wrote:

>lyallex wrote:
>
>> Actually the code does exactly what I want it to do.
>> All I know is that once I have set everything up I can do this
>> ....


>Sure. All I was saying was that your program was reading the value from
>a tree structure under .java, rather than from the .xml file that you
>were referring to. As you have shown, you can skip that import step
>completely, and still get your values.
>
>Regards,
>
>Rogan


Looks like we are in agreement then

Cool

Rgds
Lyall



"Process- How will the work and the team be organized?
The team needs to fit the culture in which it will operate,
but you should write software well rather than preserve the
irrationality of an enclosing culture" - Kent Beck
 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-07-2004

<Duncan Strang> wrote in message
news:(E-Mail Removed)...
> On Mon, 07 Jun 2004 03:15:33 GMT, "Liz" <(E-Mail Removed)> wrote:
>
> >
> >"lyallex" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed).. .
> >> On 6 Jun 2004 14:59:24 GMT, Alex Polite <(E-Mail Removed)> wrote:
> >>
> >> >Here's another newbie question?
> >> >
> >> >Is java.util.Properties the canonical way of reading and writing
> >> >configuration files?
> >> >
> >> >alex
> >>
> >> Alex
> >>
> >> I would say yes before J2SE 1.4 came out.
> >> If you are using 1.4 or later check out java.util.prefs.Preferences.
> >>
> >> Rgds
> >> Lyall
> >>

> >
> >A nit, perhaps, but in Windows the preferences are stored in the registry
> >not in a file, so it can't be a configuration file )

>
> Guess you need to read the API docs Liz
>
> http://java.sun.com/j2se/1.4.2/docs/api/index.html
>
> Rgds
> Lyall
>

Ya, you too, cuz you b wrong.

public abstract class Preferences
extends Object
A node in a hierarchical collection of preference data. This class allows
applications to store and retrieve user and system preference and
configuration data. This data is stored persistently in an
implementation-dependent backing store. Typical implementations include flat
files, OS-specific registries, directory servers and SQL databases. The user
of this class needn't be concerned with details of the backing store.


 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-07-2004

"lyallex" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 07 Jun 2004 03:15:33 GMT, "Liz" <(E-Mail Removed)> wrote:
>
> >
> >"lyallex" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed).. .
> >> On 6 Jun 2004 14:59:24 GMT, Alex Polite <(E-Mail Removed)> wrote:
> >>
> >> >Here's another newbie question?
> >> >
> >> >Is java.util.Properties the canonical way of reading and writing
> >> >configuration files?
> >> >
> >> >alex
> >>
> >> Alex
> >>
> >> I would say yes before J2SE 1.4 came out.
> >> If you are using 1.4 or later check out java.util.prefs.Preferences.
> >>
> >> Rgds
> >> Lyall
> >>

> >
> >A nit, perhaps, but in Windows the preferences are stored in the registry
> >not in a file, so it can't be a configuration file )
> >

>
>
> If you find tha API docs a bit abstract (I know I do) try
>
> http://www.javaworld.com/javaworld/j...rences-p2.html
>
> Where the preferences are actually stored doesn't matter. You can
> create and edit a preferences file, I guess that's all you need.
>
> Rgds
> Lyall
>

You can't edit a file if there is no file.


 
Reply With Quote
 
lyallex
Guest
Posts: n/a
 
      06-08-2004
On Mon, 07 Jun 2004 19:21:38 GMT, "Liz" <(E-Mail Removed)> wrote:

>
>"lyallex" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> On Mon, 07 Jun 2004 03:15:33 GMT, "Liz" <(E-Mail Removed)> wrote:
>>
>> >
>> >"lyallex" <(E-Mail Removed)> wrote in message
>> >news:(E-Mail Removed).. .
>> >> On 6 Jun 2004 14:59:24 GMT, Alex Polite <(E-Mail Removed)> wrote:
>> >>
>> >> >Here's another newbie question?
>> >> >
>> >> >Is java.util.Properties the canonical way of reading and writing
>> >> >configuration files?
>> >> >
>> >> >alex
>> >>
>> >> Alex
>> >>
>> >> I would say yes before J2SE 1.4 came out.
>> >> If you are using 1.4 or later check out java.util.prefs.Preferences.
>> >>
>> >> Rgds
>> >> Lyall
>> >>
>> >
>> >A nit, perhaps, but in Windows the preferences are stored in the registry
>> >not in a file, so it can't be a configuration file )
>> >

>>
>>
>> If you find tha API docs a bit abstract (I know I do) try
>>
>> http://www.javaworld.com/javaworld/j...rences-p2.html
>>
>> Where the preferences are actually stored doesn't matter. You can
>> create and edit a preferences file, I guess that's all you need.
>>
>> Rgds
>> Lyall
>>

>You can't edit a file if there is no file.
>


Oh, that's odd, I've just done it...

Must've been dreaming.






"Process- How will the work and the team be organized?
The team needs to fit the culture in which it will operate,
but you should write software well rather than preserve the
irrationality of an enclosing culture" - Kent Beck
 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-08-2004

"lyallex" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Mon, 07 Jun 2004 19:21:38 GMT, "Liz" <(E-Mail Removed)> wrote:
>
> >
> >"lyallex" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed).. .
> >> On Mon, 07 Jun 2004 03:15:33 GMT, "Liz" <(E-Mail Removed)> wrote:
> >>
> >> >
> >> >"lyallex" <(E-Mail Removed)> wrote in message
> >> >news:(E-Mail Removed).. .
> >> >> On 6 Jun 2004 14:59:24 GMT, Alex Polite <(E-Mail Removed)> wrote:
> >> >>
> >> >> >Here's another newbie question?
> >> >> >
> >> >> >Is java.util.Properties the canonical way of reading and writing
> >> >> >configuration files?
> >> >> >
> >> >> >alex
> >> >>
> >> >> Alex
> >> >>
> >> >> I would say yes before J2SE 1.4 came out.
> >> >> If you are using 1.4 or later check out java.util.prefs.Preferences.
> >> >>
> >> >> Rgds
> >> >> Lyall
> >> >>
> >> >
> >> >A nit, perhaps, but in Windows the preferences are stored in the

registry
> >> >not in a file, so it can't be a configuration file )
> >> >
> >>
> >>
> >> If you find tha API docs a bit abstract (I know I do) try
> >>
> >>

http://www.javaworld.com/javaworld/j...rences-p2.html
> >>
> >> Where the preferences are actually stored doesn't matter. You can
> >> create and edit a preferences file, I guess that's all you need.
> >>
> >> Rgds
> >> Lyall
> >>

> >You can't edit a file if there is no file.
> >

>
> Oh, that's odd, I've just done it...
>
> Must've been dreaming.
>

Oh, that IS odd, you must be on one of those blue hat
or jack-in-tosh machines.


 
Reply With Quote
 
lyallex
Guest
Posts: n/a
 
      06-08-2004
On Tue, 08 Jun 2004 15:36:13 GMT, "Liz" <(E-Mail Removed)> wrote:


>> >> Where the preferences are actually stored doesn't matter. You can
>> >> create and edit a preferences file, I guess that's all you need.
>> >>
>> >> Rgds
>> >> Lyall
>> >>
>> >You can't edit a file if there is no file.
>> >

>>
>> Oh, that's odd, I've just done it...
>>
>> Must've been dreaming.
>>

>Oh, that IS odd, you must be on one of those blue hat
>or jack-in-tosh machines.


Even odder, it's Microsoft Windows XP, at least it was last time I
looked, hold on ....

yes, yes, it certainly looks like XP

Yep, I'm now really really sure it is XP.

And look at this ! here's the file !!!

<!DOCTYPE preferences SYSTEM
'http://java.sun.com/dtd/preferences.dtd'>

<preferences EXTERNAL_XML_VERSION="1.0">
<root type="user">
<map />
<node name="anon">
<map />
<node name="pack">
<map />
<node name="prefs">
<map>
<entry key="outfile" value="C:/prefs/prefs.xml" />
</map>
</node>
</node>
</node>
</root>
</preferences>

Hmm, I think what you are saying is that the preferences are stored
in the registry and that the registry is not a 'file' that you can
edit. I have no argument with that, never have done. However what I am
saying is that it is possible to export those preferences to a file,
modify the file by hand, in a text editor, just like editing a
properties file then re-import the modified preferences file and have
the changes reflected in the registry.

that's all I'm saying, that's all I ever intended to say.

Still, it's good to have these little chats, it really helps to
reinforce understanding. I'm much clearer on the whole 'implementation
dependant persistence' thing now. Nice one.

Rgds
Lyall





"Process- How will the work and the team be organized?
The team needs to fit the culture in which it will operate,
but you should write software well rather than preserve the
irrationality of an enclosing culture" - Kent Beck
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Canonical" way of deleting elements from lists Robert Latest Python 12 01-09-2008 08:07 PM
Canonical way to copy an array Frederick Gotham C++ 15 08-20-2006 09:09 AM
Canonical way of dealing with null-separated lines? Douglas Alan Python 17 03-02-2005 01:25 AM
Canonical way to find if a date is valid or not ? foo Java 4 01-26-2005 08:13 PM
canonical way for handling raw data Matthias Czapla C++ 7 08-27-2003 09:42 AM



Advertisments