File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Replace words in a file by reading a properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Replace words in a file by reading a properties file" Watch "Replace words in a file by reading a properties file" New topic
Author

Replace words in a file by reading a properties file

Pete Dawn
Greenhorn

Joined: Sep 28, 2006
Posts: 17
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

Joined: Sep 28, 2006
Posts: 17
the properties file is just a simple text file and not a java properties file.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replace words in a file by reading a properties file