Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30550 > unrolled thread

Re: Reading a properties file so that keys can be retrieved in order

Started byetienne.studer@gradleware.com
First post2014-12-12 08:40 -0800
Last post2014-12-16 13:14 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Reading a properties file so that keys can be retrieved in order etienne.studer@gradleware.com - 2014-12-12 08:40 -0800
    Re: Reading a properties file so that keys can be retrieved in order Arne Vajhøj <arne@vajhoej.dk> - 2014-12-12 19:02 -0500
      Re: Reading a properties file so that keys can be retrieved in order Robert Klemme <shortcutter@googlemail.com> - 2014-12-16 13:14 +0100

#30550 — Re: Reading a properties file so that keys can be retrieved in order

Frometienne.studer@gradleware.com
Date2014-12-12 08:40 -0800
SubjectRe: Reading a properties file so that keys can be retrieved in order
Message-ID<ff033a1b-8b72-4292-b12a-90d868bf43a7@googlegroups.com>
On Thursday, May 12, 2011 9:53:59 PM UTC+2, laredo...@zipmail.com wrote:
> Hi,
> 
> I'm using Java 1.6.  Let's say I have a properties file ...
> 
> a=1
> b=2
> c=3
> ...
> 
> How can i read the properties file in Java such that when I retrieve
> the key set, the iterator structure would return the keys in the order
> they are found in the file (in the above example, "a", "b", "c")?
> 
> Thanks, - Dave

See https://github.com/etiennestuder/java-ordered-properties for a complete implementation that allows to read/write properties files in a well-defined order.

OrderedProperties properties = new OrderedProperties();
properties.load(new FileInputStream(new File("~/some.properties")));

The OrderedProperties class will solve your requirement.

Kind regards, Etienne

[toc] | [next] | [standalone]


#30557

FromArne Vajhøj <arne@vajhoej.dk>
Date2014-12-12 19:02 -0500
Message-ID<548b8203$0$294$14726298@news.sunsite.dk>
In reply to#30550
On 12/12/2014 11:40 AM, etienne.studer@gradleware.com wrote:
> On Thursday, May 12, 2011 9:53:59 PM UTC+2, laredo...@zipmail.com wrote:
>> I'm using Java 1.6.  Let's say I have a properties file ...
>>
>> a=1
>> b=2
>> c=3
>> ...
>>
>> How can i read the properties file in Java such that when I retrieve
>> the key set, the iterator structure would return the keys in the order
>> they are found in the file (in the above example, "a", "b", "c")?
>
> See https://github.com/etiennestuder/java-ordered-properties for a complete implementation that allows to read/write properties files in a well-defined order.
>
> OrderedProperties properties = new OrderedProperties();
> properties.load(new FileInputStream(new File("~/some.properties")));
>
> The OrderedProperties class will solve your requirement.

The question is 3.5 years old.

Arne

[toc] | [prev] | [next] | [standalone]


#30574

FromRobert Klemme <shortcutter@googlemail.com>
Date2014-12-16 13:14 +0100
Message-ID<cfam0mFc8d5U1@mid.individual.net>
In reply to#30557
On 13.12.2014 01:02, Arne Vajhøj wrote:
> On 12/12/2014 11:40 AM, etienne.studer@gradleware.com wrote:

>> OrderedProperties properties = new OrderedProperties();
>> properties.load(new FileInputStream(new File("~/some.properties")));

The input stream is not properly closed as far as I can see.

>> The OrderedProperties class will solve your requirement.
>
> The question is 3.5 years old.

Maybe it took him so long...

I am more concerned with the usefulness of this approach.  Properties 
are simply unordered and I think no special semantic should be applied 
to that order.  This is fragile.  If order is needed it is much better 
to choose property names accordingly and this is also what most people 
seem to do.

foo.bar.name.2=World
foo.bar.name.1=Hello
foo.bar.name.3=!

If it gets fancier than that then maybe properties are not the proper tool.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web