This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I got a requirement which needs to read the config file (properties) and display the data accordingly. But that config file may change in future.
According to that changes we need to display.
We can read the file and display by passing the key to load the property, but here we can't guarantee what key and how many properties they are adding. Is there a way to load each property one by one sequentially?
I can read the properties by
But I can't get the keys line by line (sequentially). I need that way. could someone give me suggestion on this
Im expecting the results should be displayed like the properties listed in the properties file. but I got the following out of order. This is console output
Yep, you are correct. No order is guaranteed. If you need to preserve order you are going to have to write a parser yourself. Which really isn't that hard.
If you aren't using Java5 then use the BufferedInputStream.readLine() instead of the Scanner class.
Simpson Kumar
Ranch Hand
Joined: Mar 19, 2008
Posts: 260
posted
0
Hi gregg,
Thanks for giving..
here I got a doubt.. what I'm supposed to put instead of System.getProperty("line.separator")
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35249
7
posted
0
Gregg Bolinger wrote:If you need to preserve order you are going to have to write a parser yourself. Which really isn't that hard.
Sudhakar Kumar wrote:Hi gregg,
Thanks for giving..
here I got a doubt.. what I'm supposed to put instead of System.getProperty("line.separator")
Why would you put something instead of that? If using Scanner, that tells the scanner what to break elements on. You want it to break on a new line. If you aren't using Scanner, you don't need it at all.
Simpson Kumar
Ranch Hand
Joined: Mar 19, 2008
Posts: 260
posted
0
Gregg Bolinger wrote:
Why would you put something instead of that? If using Scanner, that tells the scanner what to break elements on. You want it to break on a new line. If you aren't using Scanner, you don't need it at all.
I got read properties sequentially with Scanner, now I will implement that into my real code. let me try..
Rob Prime wrote:Are those really your field names? And will they always be "fieldX.readOnly" etc? If so, you can use the following technique:
This code will continue as long as the field for the index is there. You can't have any gaps, but the number of fields can be virtually unlimited.
Hey Rob, I tried your logic too, I feel this one is good and easy and it works. Thanks
Now I need another clue, how to read updated properties file without rebooting the server?
Generally if we update the properties file, we need to reboot the server in order to load updated properties. Is there any approach to avoid rebooting?