Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem in writing special charactes to a proeprties file

 
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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 \\:

 
Nothing? Or something? Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic