I am trying to load all the property names present in the properties file using the below code:
for(Enumeration<String> en = (Enumeration<String>) prop.propertyNames();en.hasMoreElements();){
String key = (String)en.nextElement();
System.out.println("Property name is "+key);
}
But my properties file has the below contents:
username=
password=
Parent file name=
Child file name =
After running the code I am getting output as :
username password Parent Child
If the property name has spaces, it is only returning the first word..
Can any one please tell me how to do this?
You can escape the spaces in your properties file, but I think it will start to look pretty ugly.
username=a
password=b
Parent\ file\ name=c
Child\ file\ name=d
You might be better of writing your own implementation with split()
or indexOf()
or whatever your heart desires to avoid any future bugs and/or headaches.
In Java.util.Properties
, =
, :
, or white space character are key/value delimiter when load from property file.
Below are detailed Javadoc of its public void load(Reader reader)
The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped
=
,:
, or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character. http://docs.oracle.com/javase/6/docs/api/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With