Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better way to represent array in java properties file

I'm currently making a .properties file that needs to be loaded and transformed into an array. But there is a possibility of anywhere from 0-25 of each of the property keys to exist. I tried a few implementations but i'm just stuck at doing this cleanly. Anyone have any ideas?

foo.1.filename=foo.txt foo.1.expire=200  foo.2.filename=foo2.txt foo.2.expire=10  etc more foo's  bar.1.filename=bar.txt bar.1.expire=100 

where I'll assemble the filename/expire pairings into a data object, as part of an array for each parent property element like foo[myobject]

Formatting of the properties file can change, I'm open to ideas.

like image 242
yep Avatar asked Aug 10 '11 17:08

yep


People also ask

How do you represent an array in Java?

type var-name[]; OR type[] var-name; An array declaration has two components: the type and the name. type declares the element type of the array. The element type determines the data type of each element that comprises the array.

What is the advantage of properties file in Java?

The advantage of using properties file is we can configure things which are prone to change over a period of time without the need of changing anything in code. Properties file provide flexibility in terms of configuration. Sample properties file is shown below, which has information in key-value pair.


1 Answers

I can suggest using delimiters and using the

String.split(delimiter)

Example properties file:

MON=0800#Something#Something1, Something2

prop.load(new FileInputStream("\\\\Myseccretnetwork\\Project\\props.properties")); String[]values = prop.get("MON").toString().split("#"); 

Hope that helps

like image 98
Abs Avatar answered Oct 17 '22 18:10

Abs