How do you want your map to be structured?
I noticed <Integer,
String>. So thats line number,line? or tokenNumber,token?
Anyway you need to populate your map according to your requirement.
Since you have code to read from a file, it should be simple to write back. Conceptually it is exactly the opposite of reading from the file.
Which part are you stuck in writing?