How can I find a substring in a file already in a hashmap?

I have a hashMap (guava bimap) where the keys and values ​​are both strings, I wanted to write a program that parses a given file and replaces all the lines in the file that are also in BiMap with the corresponding values ​​from Bimap.

eg: I have a file named test.txt has the following text Java is a set of several computer software and specifications developed by Sun Microsystems.

and my BiMap "java i" => "value1" "everal computer" => "value2"


So now I want my program to take test.txt and Bimap as input and produce a result that looks something like this.

value1s a set of svalue2 software and specifications developed by Sun Microsystems.


please point me to any algorithm that can do this, the program takes large files as input, so brute force might not be a good idea.

Edit: I am using fixed length strings for keys and values. This example was just meant to show the operation. Thank you.


source to share

1 answer

For a batch operation like this, I wouldn't be putting a lot of data into memory. Therefore, I would recommend that you write your new content to a new file. If the file at the end should be the same file, you can still replace one file with another at the end of the process. read, write and erase each new line separately and you won't have any memory issues.



All Articles