Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8403223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:17:09+00:00 2026-06-09T22:17:09+00:00

With the following properties file: foo=hello, world! bar=first,second I would like to retrieve the

  • 0

With the following properties file:

foo=hello, world!
bar=first,second

I would like to retrieve the first item as a string and the second as an array. I would have thought that getString vs getStringArray would deal with this, but it doesn’t – getString("foo") just gets everything before the comma, i.e. “hello”.

If I disable delimiter parsing using setDelimiterParsingDisabled, foo is fine, but this also changes the behaviour of getStringArray("bar") to return a single-element array!

I can’t find how I can explicitly tell it how I want it to interpret an individual config item, either as a string or as an array. I don’t want to put the config items into separate config files with different delimiter rules, and I’d prefer to use a comma as the delimiter for the getStringArray case.

To elaborate, this snippet prints either hello - 2 or hello, world! - 1 – I want it to print hello, world! - 2 !

AbstractFileConfiguration config = new PropertiesConfiguration();
config.setFileName("C:\\temp\\temp.properties");
//config.setDelimiterParsingDisabled(true);
config.load();
System.out.println(config.getString("foo") + " - " + config.getStringArray("bar").length);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:17:11+00:00Added an answer on June 9, 2026 at 10:17 pm

    As you found out, Commons Config lacks something like a getPlainString() method. Here are some suggestions for workarounds.

    I think using a different list delimiter is the easiest to implement. If you need something more complex, consider the other two:

    Use a different list delimiter with setListDelimiter()

    Works as long as you don’t need to interpret the same value as a String and as an array.

    properties file:

    foo=hello, world!
    bar=first;second
    

    Code:

    AbstractFileConfiguration config = new PropertiesConfiguration();
    config.setFileName("C:\\temp\\temp.properties");
    config.setListDelimiter(';');
    config.load();
    System.out.println(config.getString("foo") + " - " + config.getStringArray("bar").length);
    

    Disable delimiter parsing and do your own splitting

    Easily done with String.split(). A simple static method will do:

    public static String[] gerStringArray(Configuration config, String key)
    

    Or create a subclass of PropertiesConfiguration and override the getStringArray() and getList() methods.

    Use two different configurations

    One for settings data where you know what format the data will have. Here you can activate delimiter parsing.

    And one for text data where you might have arbitrary data. Here you should deactivate delimiter parsing.

    This has the additional advantage of separating settings and text data.

    • Not mixing settings and text data keeps both configurations cleaner. Especially if there’s a lot of both.
    • Often settings data changes depending on the deployment environment (live/test) while text data changes depending on the locale (en_GB/de_DE).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a simple properties file with the following entries: my.value=123 another.value=hello world
Assign object literal properties var foo = { bar : 'hello'}; Ternary var cats
I've got a properties file in my classpath with items like the following PI20=Fältet
I have the following log4j.properties file: log4j.rootLogger=DEBUG,A1,A2,A3 log4j.appender.A1=org.apache.log4j.RollingFileAppender log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.File=log.out log4j.appender.A1.MaxFileSize=100KB log4j.appender.A1.MaxBackupIndex=1 log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%p
Can you do the following with a Java ResourceBundle? In the properties file... example.dynamicresource=You
I am reading data from a text file with following properties: Encoding: ANSI File
I have a properties file, which, when unmodified has the following line: worker.list= I
I have the following code trying to read a properties file: Properties prop =
I have a class with the following properties: Message(string), Added(DateTime) and LogLevel(string) In my
I have the following entry in a properties file: some.key = \n [1:Some value]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.