I have written a code wherein i am reading a properties file and adding the values to a hashmap and using it in a specific format to call an API. Problem is slash space (\ ) is replaced with a space. Adding the code:
public class propertfile {
public static void main(String[] args) {
FileInputStream fis;
try {
fis = new FileInputStream("path_to_properties_file");
ResourceBundle resources = new PropertyResourceBundle(fis);
Map<String, String> map = new HashMap<String, String>();
//convert ResourceBundle to Map
Enumeration<String> keys = resources.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
map.put(key, resources.getString(key));
}
//Now you can use the 'map' object as you wish.
Iterator < Entry<String, String> > new_Iterator = map.entrySet().iterator();
JSONArray jsonArray = new JSONArray();
while (new_Iterator.hasNext()) {
JSONObject jo = new JSONObject();
Map.Entry<String, String> new_Map = (Map.Entry<String, String> )
new_Iterator.next();
JSONObject requestParams = new JSONObject();
requestParams.put("name", new_Map.getKey());
requestParams.put("value", new_Map.getValue());
jsonArray.put(requestParams);
}
System.out.println(jsonArray);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Actual properties file :
databases.my1_analysis.folder.1..\ db\ connection.datasources.custom.ds_sap_bap.Enable\ SNC=false
Desired with missing slash space: (Notice after the number 1.. , after db and also after Enable)
{"name": "databases.my1_analysis.folder.1.. db connection.datasources.custom.ds_sap_bap.Enable SNC", "value": "false"}
Any help is highly appreciated.