|
-
March 1st, 2010, 11:19 AM
#1
Reading a properties file
I am looking for a better method to read a properties file. My program loads and does a loop with some processing based on a properties file. The properties file can be changed on the fly to change how the loop runs or what processing is performed.
Here is what I do right now:
The config file has values like this:
source=c:\data\data.txt
Code:
string[] configProp = File.ReadAllLines(@"config.properties");
I load the file into a string array. I then proceed to reassign string array value into a new string and perform trims to remove the leader "source=" and I am left with "c:\data\data.txt" which is my usable variable.
This just seems like a lot of extra work, does anyone know of a better way to load a properties file?
-
March 1st, 2010, 08:27 PM
#2
Re: Reading a properties file
Try this:
Code:
IEnumerable<KeyValuePair<String, String>> properties = from p in File.ReadAllLines(@"config.properties")
select new KeyValuePair<String, String>(
p.Split(new Char[] { '=' })[0],
p.Split(new Char[] { '=' })[1]);
foreach(KeyValuePair<String, String> property in properties)
{
...
}
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
March 2nd, 2010, 02:39 AM
#3
Re: Reading a properties file
Is properties file a must, or can you use other format, e.g. .NET"s common config file? If so, there are plenty classes in System.Configuration namespace which can help you.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|