Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set empty string as the value of a key in properties file

Tags:

jdbc.password=

How can I assign jdbc.password key in my application.properties file an empty string?

I understand I can do this programmatically as follows, but I would like to set this in properties file.

Properties props = new Properties();
props.put("password", "");
like image 517
Susie Avatar asked Sep 12 '14 00:09

Susie


People also ask

How set value in properties file in Java?

To set properties in a Java Properties instance you use the setProperty() method. Here is an example of setting a property (key - value pair) in a Java Properties object: properties.


1 Answers

Just leaving the value empty on the RHS should be fine:

password=

Sample code:

import java.io.*;
import java.util.*;

class Test{
    public static void main(String [] args) throws Exception {
        Properties props = new Properties();
        props.load(new StringReader("password="));
        System.out.println(props.size()); // 1
        System.out.println(props.getProperty("password").length()); // 0
    }
}
like image 91
Jon Skeet Avatar answered Sep 28 '22 08:09

Jon Skeet