File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Properties file" Watch "Properties file" New topic

Properties file

Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Is there any specific switch to pass a Properties file from the command line?

Normal is in the eye of the beholder
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
None that I can see.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
nope. You need to parse the commandline yourself and determine which is the properties file.
Or more likely you will force a specific name and location on the file and read it from there.
Or have another properties file at a specific name and location and read the name and location of the properties file from there

Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
I guess I was looking for something of the Properties class in conjunction with the -D switch... Rather then saying arg1=value1 arg2=value2 ... to pass a file.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
If you pass the pathname to the file into the main method, you can create from that String a FileInputStream which can then be loaded into a Properties object.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You could also use the -D option in conjunction with some new system property - e.g.
java MyClass
Then use that system property to load the Properties:

"I'm not back." - Bill Harding, Twister
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
What a KISS rule! Thanks JRY
I think the Properties file should not be part of cmd-line-args-validation and your solution is a compromise.
I agree. Here's the link:
subject: Properties file
It's not a secret anymore!