I'm currently struggling to find out if there is a way I can get the Key from the Key-Value pair in a properties file.
As far as I am aware getProperty(String Key) can return the value from the Key-Value pair, but what if I know the Value but want to find out what the Key is.
Is this possible?
Neil Tomlin wrote:well I'm thinking particularly of the mime.types file that I have loaded into a properties file
I know that my file type is a gif
I want image/gif
Can I get it?
Reverse your key/value pairs. Especially in this case it would seem to make sense...what if you have more than one file extension for which you want to use the same mime type? You can have duplicate values but you can't have duplicate keys. Imagine you have .html and .htm and you want to use the same mime type 'text/html' for both.
You can have this in your properties file:
but you can't have this:
One of these values will be overwritten by the other in the underlying hashtable. The other alternative could be do something like:
and tokenize the property value on the comma
Neil Tomlin wrote:Apologies to continue asking questions, but how can I reverse it? I've just loaded it into a properties file straight from mime.types.
Since you said you loaded it into a Properties FILE I assumed you meant you literally copied the content of the mime.types file into a .properties file and that you were then reading in that .properties file so I assumed you could edit the .properties file since I assumed you had created it. Now, I'm guessing what you probably mean to say is that you loaded the mime.types file into a Properties object??