• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Merging Property files

 
Prasanna Puttappa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a requirement to merge two property files with features below
1.Maintain order of attributes i.e., order of keys should not be disturbed after merge
2. Comments should be retained.

is there any standard utility api for the above requirement
OR
any suggestions ?

Thanks,
------------
[ August 08, 2005: Message edited by: Prasanna Kumar BP ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you could use Readers for both files, reading them line by line, and writing out the result in whichever way you need to. Only thing to watch out for would be continuation lines, i.e. properties that span more than one line. Also, be careful to specify the proper file encoding.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to Ulf's post in a somewhat orthogonal but complementary way: consider using LinkedHashMap rather than Properties. This will allow you to maintain insertion order (of course you will need to decide which o the two properties fields comes first) while maintaining the basic contract of a Map (which Properties extends, and if you're using JDK 5.0 there's little reason to continue using Properties anyway). Ulf's post suggests how to read the file; this post suggests where to put the contents of the file after it's been read. Between the two, you may be able to achieve your goals.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic