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 properties files, initial directory, etc... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "properties files, initial directory, etc..." Watch "properties files, initial directory, etc..." New topic
Author

properties files, initial directory, etc...

Ben Carlson
Greenhorn

Joined: Nov 25, 2001
Posts: 3
Hello Everyone!
I am having a fair bit of trouble with properties files, namely how to ensure that they are in the same location on various platforms without recompiling.
I develop in Windows at work, and on Linux at home, and every time I transfer code, I have to edit my classes and recompile so they have the proper path... example:
c:\apps\search\.properties //windows
/home/bcarlson/apps/search/.properties //Linux
I would have assumed(silly me!) that I should be able to place a .properties file in a dir in the classpath and just use:
Properties defaultProps = new Properties();
try {
defaultProps.load(new FileInputStream(".properties");
} catch (IOException e) {
....etc...
to grab from my /home/bcarlson/apps/search dir...? any thoughts? Examples of how you've solved this? I'm probably missing something simple, because I assume most people use .properties files on a regular basis... ?
Thanks so much!!
Ben Carlson
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You could take in the location of the properties file as a parameter.
>java myAppp MyPropertiesFileLocation.properites
Then you invoke your application using a .bat file or whatever (this would need to be specific per platform).

"JavaRanch, where the deer and the Certified play" - David O'Meara
Ben Carlson
Greenhorn

Joined: Nov 25, 2001
Posts: 3
That's a really good idea, one I hadn't thought of! DOH!
Ok, not to beat a dead horse, but, on the same train of thought, is there a way to reference a txt/xml/html file using the class style path (i.e. "com.foo.bar.xml")? I can see some issues, but it seems reasonable that others would have similar problems... ?
Thanks again for your quick answer, Cindy!
Ben Carlson
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I don't think so. The problem is that the claspath stuff is interpreted by the compiler - so Sun could re-work syntax all that they wanted.
However file locations are eventually passed to the OS to work with - and the OS expects their syntax to be honored.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Ben Carlson:
[B]I would have assumed(silly me!) that I should be able to place a .properties file in a dir in the classpath and just use:to grab from my /home/bcarlson/apps/search dir...? any thoughts?[/B]
Easy. Try this.Put the ".properties" file in the same location as the .class file for the above class. If you want the properties to reside in the root of the class hierarchy, use getClass().getClassLoader().getResourceAsStream().
- Peter
 
 
subject: properties files, initial directory, etc...