Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replace words in a file by reading a properties file

 
Pete Dawn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

am working on file which contains the following many lines of data,
Message, String1, String2, String3, String4

Now string1, string2, string3, string4 are alphanumeric codes. now i need to read a properties text file which contains the strings associated with these codes.
eg. "String1"="Test Message"

so i need to parse my file and replace all occurences of codes with their respective strings (from the properties file).

am not sure how should i go about it. please help. thanks.
 
Pete Dawn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the properties file is just a simple text file and not a java properties file.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pete,

Well to start off with you'll want to look at the File I/O tutorial which will quickly guide you on how to read in data from a file and write data to a file (including line by line etc).

Depending on your memory/performance limitations I'd be tempted to read in the properties file and store the key/value pairs in a Map. Whether you try to replace the keys in the actual file 'on the fly' (more difficult) or write out a new file (easier but you'll need to rename the original file etc) is then up to you.

Hope that sets you on the right path!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic