I am using a java .properties file in order to save multiple different connection details. However the way I am currently doing it is very messy and I feel as though I could benefit from using the storeToXML() functionaltiy. But I am currently struggling to get my head around it and get the desired output.
The data is currently input by the user via GUI. When the user clicks "add" the data(serverIP etc) is added to a List of type String. The JTextFields are reset to "" and that list is added to a List of types List, the user can then add another connection if they wish...This, in effect, gives me a 2D ArrayList.
When the user clicks "save profile" the 2D ArrayList is iterated through in a forloop and the value of the loop index (i) is appended to the property key. eg serverIP0=...
My properties file currently looks like this:
serverIP0=255.255.255.255
user0=username
password0=password
serverIP1=123.123.123.123
user1=username
password1=password
serverIP2=10.10.10.100
user2=username
password2=password
etc.
I would like the data to be stored like this:
<myProfile>
<Connection>
<serverIP>123.123.123.123</serverIP>
<user>username</user>
<password>password</password>
</Connection>
<Connection>
<serverIP>255.255.255.255</serverIP>
<user>username</user>
<password>password</password>
</Connection>
<Connection>
<serverIP>10.10.10.100</serverIP>
<user>username</user>
<password>password</password>
</Connection>
</myProfile>
So my question is, with my current set up, how would I store my properties file in the way I've laid out above. Or better yet, is there a better way to do this altogether.
Additional Info: My application displays a dropdown box on launch containing all the properties files it can find in a designated folder. So these properties files would need to be loaded back into an array if possible, but I haven't got to that stage yet.
Any help is much appreciated.
No comments:
Post a Comment