How to write properties file in Groovy without escape characters and single quotes?

escaping, groovy

Solution

You could do this:

def newProps = new Properties()
newProps.setProperty('SFTP_USER_HASH', 'woo')
newProps.setProperty('GD_SFTP_URI', 'ftp://woo.com')

propsFile.withWriterAppend( 'UTF-8' ) { fileWriter ->
    fileWriter.writeLine ''
    newProps.each { key, value ->
        fileWriter.writeLine "$key=$value"
    }
}

BUT, so long as you are reading the properties in with `load`, there should be no need for this as it should de-escape any escaped characters

Problem

I have something like: ``` def newProps = new Properties() def fileWriter = new OutputStreamWriter(new FileOutputStream(propsFile,true), 'UTF-8') def lineSeparator = System.getProperty("line.separator") newProps.setProperty('SFTP_USER_HASH', userSftpHome.toString()) newProps.setProperty('GD_SFTP_URI', sftpHost.toString()) fileWriter.write(lineSeparator) newProps.store(fileWriter, null) fileWriter.close() ``` The problem is that store() method escapes ":" or "=" characters with backslash (). I don't want that because I store there some passwords and tokens and need to copy those values strictly in the key=value format. Also, when I use the configSlurper, it stores the values with single quotes, like: ``` key='value' ``` Is there any solution for that? Saving in unescaped key=value format to properties file in Groovy?

Original source

Related problems