• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in writing special charactes to a proeprties file  RSS feed

 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to add key value pairs to a properties file.the values are separated by # , ; , =,-.
All are working fine except # and = everytine a \ is appended before the characters.
Please share me any suggestion for making this possible.

Regards,
amarshi
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is by design. Since characters such as # and = have a special meaning in properties files, they need to be escaped with a \ if you want to include a literal # or = in the properties file. That's just how Java properties files work.

If you remove the \ somehow, then class java.util.Properties might not be able to load the file properly, so I suggest you just leave the \ in there.
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with
append("\'=") and also append("\=\")..
but still the problem exists.
can you share me the syntax?

Regards,
amarshi
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you want to do? Note that the correct way to read and write a properties file is to use the load() and store() methods of class java.util.Properties. This will automatically (un)escape special characters, so you don't have to deal with those special characters yourself.

In Java source code, the \ has a special meaning. If you want to include a \ in a string literal, you'll have to write \\:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!