Development projects would need internationalization generally. Most people use property files backed by a ResourceBundle to support it. Developers tend to keep different property files for different countries and keep adding new keys and values whenever they need. If you are a developer, you might have already been there in a situation where once in a while you would need to clean up the property files and remove duplicates. Removing the duplicate keys and values from a property file helps you to reduce the size of the file. Here’s how to remove duplicates from a properties file easily.

If you do the removal of duplicates from property file manually, it will take years to finish. Instead, you can do it programmatically so that you can do it less than a second. Here’s such piece of code which is written to remove the duplicate keys and values from a property file. It takes the input from a file and writes output to a different file. It is written in Java, you can copy and paste the code to any editor and run directly without any additional dependencies.

You need to replace PATH_TO_INPUT_PROPERTY_FILE with the path to the property file to be processed. Also, PATH_TO_OUTPUT_PROPERTY_FILE should be replaced with the output file name you want.

The above code is just basic and you are welcome to make any modifications to it such as reading a bunch of files and process it together.

Share this article:

Leave a Reply

Your email address will not be published. Required fields are marked *