commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [Configuration] problems with changing the delimiter
Date Sun, 25 Feb 2007 16:34:27 GMT
Ole Wendland wrote:
> Hello Guys,
> please tell me whats the problem with this delimiter.
> The Program is this one:
> 
> import org.apache.commons.configuration.*;
> import java.io.*;
> import java.util.List;
> 
> class SaveProperties
> {     public static void main( String[] args )
>  {
> 
>      try {           PropertiesConfiguration config = new
> PropertiesConfiguration("test.txt");
>         config.setListDelimiter('|');
>       
> System.out.println(System.out.println(config.getList("test").get(0));
> 
>    } catch (ConfigurationException e) {
>        // TODO Auto-generated catch block
>        e.printStackTrace();
>    }
>  }
> }
> 
> and the test.txt looks like this
> test = one|two|three
> 
> The output I expect should be "one" but he can't split the List and
> gives me  "one|two|three". When I use a comma as Delimiter is everything
> fine.
> What is my mistake?
> 
> Greetings Ole

You have to set the delimiter before you load the configuration. Follow
this pattern:

PropertiesConfiguration config = new PropertiesConfiguration();
config.setListDelimiter('|');
config.load("test.txt");

(There is a note about this behavior in the Javadocs for the
setListDelimiter() method in AbstractConfiguration.)

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message