I tried a lot, but was unable to find a solution.
|
|--src/main/resouces
|
|-updatePropertiesFile.java
|-xyz_en_US.properties
|-xyz_en_AF.properties
|-xyz_en_AE.properties
This is my project structure.
I have a updatePropertiesFile class, to update a key for all the properties file. I have around 200 properties file.
So what I need is that, I need to write a method to update a particular key in all these properties file. Manual change is not that practically. I need to write an application which does this funtionality.
I tried using resoucebundle mechanism. But using resource bundle, we can get only one property file. I tried ResourceBundle.getBundle(String,Locale)
and ResourceBundle.getBundle(String)
methods.
I need an iteration through these properties file and updation for the key.
My initial issue is fixed.
I did this as :
File[] files = new File("src/main/resources").listFiles();
for (File file : files) {
if (file.getName().endsWith("properties")) {
//my logic
}
But when I did this, my comments in properties file got removed and the order got changed. I wnat to keep the order of the key and the comments in properties file too.
To keep the order I tried using:
public static class LinkedProperties extends Properties {
private final HashSet<Object> keys = new LinkedHashSet<Object>();
public LinkedProperties() {
}
public Iterable<Object> orderedKeys() {
return Collections.list(keys());
}
public Enumeration<Object> keys() {
return Collections.<Object>enumeration(keys);
}
public Object put(Object key, Object value) {
keys.add(key);
return super.put(key, value);
}
}
But this caused some changes in key-value pair in properties file. Some special character got added up.
Please help me out to maintain the comments and order