It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Questions about properties files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Questions about properties files" Watch "Questions about properties files" New topic
Author

Questions about properties files

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Hello,
I have two questions about properties files.
1. Is it possible to import a properties file from another properties file?
2. Is it possible to have variables in a properties file as described below in code snippet.
Thanks in advance,
Julien.

Code snippet:

var_one=foo
var_two=$var_one bar

The second line would then read "foo bar"
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41042
    
  43
to 1) No. You can load two files into two Properties objects, and merge them using the putAll method, though.

to 2) Not exactly like that. You can use "var_two={0} bar", and then {0} (and {1} etc.) is a variable that you can set programmatically later, but you can't directly reference other properties like in your example.


Ping & DNS - my free Android networking tools app
Joseph Sillitoe
Greenhorn

Joined: Dec 30, 2005
Posts: 12
Acctually,

1) Yes, kind of. Suppose you have two properties files in the "resources" directory (which also is in the classpath). The names of the files could be:
  • propfile1.properties
  • propfile2.properties


  • The contents of the "propfile1.properties" file could include:



    Then it would be a matter of loading the first properties file, extracting the name of the second one, and then loading that one as well.




    Jeff Albertson
    Ranch Hand

    Joined: Sep 16, 2005
    Posts: 1780
    Originally posted by Julien Martin:

    2. Is it possible to have variables in a properties file as described below in code snippet.

    var_one=foo
    var_two=$var_one bar

    The second line would then read "foo bar"

    Ant lets you write property files like that, in Ant syntax, of course:

    var_one=foo
    var_two=${var_one} bar

    I would suggest you check out Ant's API and see if you can reuse some of its functionality.


    There is no emoticon for what I am feeling!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Questions about properties files
     
    Similar Threads
    resourcebundle
    Log4j : How to name the logfile dynamically
    JavaBean with Property Descriptor file example
    instanceof
    Class path question