0

I have this function to save in a file my properties:

 void saveProperties(Properties properties) {
    File file = new File("C:\\Files\\new.properties");
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    properties.store(fileOutputStream, "Properties");
}

My problem is that when I want to save in a file the properties below using my function:

myPropertieTest1=Hi : friend
myPropertieTest2=#Bye
myPropertieTest3=!#:

My code added an escape character like this:

myPropertieTest=Hi \: friend
myPropertieTest2=\#Bye
myPropertieTest3=\!\#\:

How can I fix this? I need to save the properties as the originals (without the escape characters)

Despotars
  • 541
  • 1
  • 8
  • 23
  • 1
    I've found similar question. May this helps you https://stackoverflow.com/questions/10699055/how-do-you-escape-colon-in-properties-file – Artem Evdokimov Jan 26 '22 at 18:59
  • This is just how Java properties are stored, with the escapes. If you don't want the escapes, then using Java properties isn't the way you should be doing it. – Louis Wasserman Jan 26 '22 at 19:16
  • Hi @Atryom, my problem here is that after adapt my code like you show me in that post, now when saving a property, Java is interpreting the property and if it finds \n it does a line break and saves a new property , do you know the way to fix that? – Despotars Feb 17 '22 at 14:11
  • I didn't quite catch. Are you trying to save a property, which name or value contains `\n` ? If you have updated your code, could you please update the question as well – Artem Evdokimov Feb 17 '22 at 18:47

0 Answers0