Now my doubt is that when i read the second file using streams and if i find the name as A,B or C then i have to replace them with their names in the first file like A-first letter;B-second letter;C-third letter.........I am bit confused about the structure of the program or how to read first file and make changes in the second file. My program for reading the second file is:
 Note: if the values==A then it should be changed to "firstletter" or if its B then it should be chnaged to "Second letter" by reading the first file.How to insert here the coding and the structure please.
[ edited to preserve formatting using the [code] and [/code] UBB tags, to remove the evil tab characters, and to move a comment and question out of the code -ds ] [ September 17, 2004: Message edited by: Dirk Schreckmann ]
Find and Replace is pretty simple, all you need to do is, for every line you read from 1st file, you want 'xxx' to be replaced with some text, so call a method by passing line as parameter and in that method, you read second file and return a match string to replace. So, the calling method would have code something like this:
A good solution might be to read the entire contents of the first file into a map data structure. As you come across keys in the second file, use them to look up the replacement values in the map, populated from the first file.
Concerning replacing part of a string, are you able to replace the "XXX" in the string, "How are you, XXX?"
An easy way to effectively change the contents of a file might be to simply create a differently-named new file with the desired contents, completely delete the old file, then rename the new file to that of the deleted old file. Or you could read the entire contents of the old file into memory, apply the content changes in memory, delete the old file (or just the contents of the old file), then create a new one with the same name and write the changed data to it.