Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.properties  RSS feed

 
deneb shah
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say that there is a file "abc.txt". in that file i have
zzz = xxx
ddd = eee
....
I could read the file using buffered reader.like
bfr.readline() and populte my variables in my file.
the other i could use is the with the help of the Property class.
like Property p = new Property();
p.load(new FileInputStream("abc.txt"));
then i coud use p.getProperty("ddd");
...
According to me the second methodis a better method the reason is that the file reading is done in one shot. the first method involves a lot of io opertions...
Am i correct ???
Furthur could i claim that always use the second method...
One of the reasons is that in my project there is some inefficinecy in terms of the time and the memory.. that is the reason why i m asking u...
Sorry for the question being too long or if u havent understood the question i would try to make it better.
Thnx
------------------
denice the menace
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is a good method to use in general. Its big advantage is the savings of development time - they've already done most of the work for you. I don't see any reason to think that the algorithms implemented by Sun will be any slower than one you implement yourself - they will probably be faster, unless you put significant effort into optimizing your code. Either way, the amount of IO operations should be the same - the whole file has to be read once. It's just a question of whether you write the code to do that, you Sun does.
There are a few possible downsides to be aware of when using Properties like this:
All the variables in Properties are Strings. If you want anything else, you'll need to convert them yourself.
Some characters require special escape sequences to represent. I don't know where this is documented or if this is system-dependant, but if I want a \ in a property, the input file has to contain \\. At a guess, this probably follows the same rules for converting string literals into strings, (e.g. newline is \n, etc) but I haven't found where this is specified for Properties. If your input data contains these special characters, you may or may not find it convenient to put in the proper escape sequences.
Each time you access a particular property, it takes some time. To do this once per property I doubt the performance will be any worse than it will be for your own algorithm, but if you access the same property repeatedly, there's usually a better way. For example:
<code><pre> for (int i = 0; i < 100; i++) {
String ddd = p.getProperty("ddd")
doSomething(ddd);
}</pre></code>
This would be faster as:
<code><pre> String ddd = p.getProperty("ddd")
for (int i = 0; i < 100; i++) {
doSomething(ddd);
}</pre></code>
An extreme and hopefully somewhat obvious example, but it could appear in more subtle form in some programs.
Well, those are my thoughts. I hope this was helpful.

[This message has been edited by Jim Yingst (edited March 30, 2000).]
 
deneb shah
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Jim
u r a dude .....
u r rightly THE e-SHeRiFF....
.. hope that u continue ur spirit of advising others and encouraging to post questions..
thnx
------------------
denice the menace
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!