File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Questions about properties files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 383
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: 35241
    
    7
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.


Android appsImageJ pluginsJava web charts
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
     
    subject: Questions about properties files
     
    Similar Threads
    Log4j : How to name the logfile dynamically
    JavaBean with Property Descriptor file example
    Class path question
    instanceof
    resourcebundle