File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes property files (Why does java make this so hard?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "property files (Why does java make this so hard?)" Watch "property files (Why does java make this so hard?)" New topic

property files (Why does java make this so hard?)

Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
All I want to be able to is avoid having to hard code some values in my code.
So I assumed that I should stote this information in a "properties" file, right? (Maybe this is my mistake) Well anyways please take a looks at this ...
bash-2.03$ cat
property_1 value1 value2 value3 value4
bash-2.03$ cat
import java.util.*;

public class MyProps {
public static void main(String[] args) {
Properties myProps = new Properties();
String propFileName = "";
InputStream is =
( propFileName );
myProps.load( is );
System.out.println( "props = [" + myProps + "]" );
... let me know what I am suppose to do.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
The secret is in the classpath. Put the .properties file in your classpath, just like your .class file(s) are. To open the input stream:
InputStream propStream = getClass().getResourceAsStream("/");
I agree. Here's the link:
subject: property files (Why does java make this so hard?)
jQuery in Action, 3rd edition