How do I escape the hash sign (#
) in Java properties files.
We have an internationalization framework that uses Java properties files.
There is a column called number and we want its header to be #
. This ...
number=#
... doesn't work.
I have a properties-file containing special chars in its key and value part, like #, :, ! or just a simple space. All occurences are escaped with a backslash, but IDEA marks all occurrences in the value element red.
Since it is java, you need to replace hash( # ) with \\# in your code. Notice the double slashes. Alternately you can replace # with \\u0023 .
util. Properties. clear() method is used to remove all the elements from this Properties instance. Using the clear() method only clears all the element from the Properties and does not delete the Properties.
properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.
This one should work without any escape character:
number=#
Just made a small test using code ....
prop.load(new FileInputStream ("./res/app.properties"));
System.out.println("Property: " +prop.getProperty("Number"));
... and property file (note upper/lower case):
Number=#
Text=test
Result:
Property: #
So rather check your spelling, lower/upper case or further processing.
Check out this or that one (linking Java documentation too) for more.
p.s.: though it shouldn't be required you could also try the Unicode sequence: \u0023
.
Cheers!
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