0

I have a property file in my project, say config.properties, having a property field project.searchkey. Can I have the value of this field as project.searchkey = 'one','two'?

Will it be considering both the values with the '' sign?

Mike
  • 721
  • 1
  • 17
  • 44
  • 2
    That depends on the software that's reading and using the properties file, and since we don't know what software that is, we cannot tell you. – Jesper May 16 '18 at 12:07
  • 1
    Depends how you will work with that file, if you will use common [`Properties` and `FileInputStream`](https://stackoverflow.com/a/1318391/4892907) then it should not matter... Btw isnt it faster simply try, then ask? :) – xxxvodnikxxx May 16 '18 at 12:09
  • 1
    why don't you just try? – Bentaye May 16 '18 at 12:16

2 Answers2

1

Using java.util.Properties (see API)

public class Main {
    public static void main(String[] args) {
        Properties prop = new Properties();
        try {
            prop.load(Main.class.getClassLoader().getResourceAsStream("config.properties"));
            String propertyValue = prop.getProperty("project.searchkey");
            System.out.println(propertyValue);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

It prints 'one','two', so it reads everything after the = as a single String

project.searchkey='one','two' returns 'one','two'

project.searchkey=one,two returns one,two

project.searchkey=one, 'two' returns one, 'two'

etc ...

Bentaye
  • 9,403
  • 5
  • 32
  • 45
1
project.searchkey=one, two, \
                  three, four, \
                  five

Best not to have keys with commas, and hence not needing single quotes. After retrieval of the String value for key "project.searchkey":

String value = bundle.getProperty("project.searchkey");
// value is "one, two, three, four, five"
String[] searchKeys = value.split(",\\s*"); // Split by comma and any whitespace.

Of course single quotes could be removed for value.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138