Results 1 to 3 of 3
  1. #1
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default Load A Property File From Classpath?

    im using this code
    Java Code:
    public class PropertiesLoader {
    
    	
    	  public Properties getPropertiesFromClasspath(String BankProperties) throws IOException {
    	      
    	        Properties props = new Properties();
    	        InputStream inputStream = this.getClass().getClassLoader()
    	            .getResourceAsStream(BankProperties);
    
    	        if (inputStream == null) {
    	            throw new FileNotFoundException("property file '" + BankProperties
    	                + "' not found in the classpath");
    	        }
    
    	        props.load(inputStream);
    
    	        return props;
    	    }
    	
    }

    and im trying to call the method and in reviving the exception im think that i should put something else instead of BankProperties but what??

  2. #2
    jackGav is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    hi,
    your method is fine, but take into account that you have to call it including in the name of the properties the path of your package.
    For instance if your property file has the name of "test.properties" and if located in the package "com.sample" then you have to call your method as below:

    Java Code:
    getPropertiesFromClasspath("com/sample/test.properties");

  3. #3
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

Similar Threads

  1. File Property
    By Juggler in forum New To Java
    Replies: 0
    Last Post: 08-10-2008, 08:23 AM
  2. How to store property file into key value pair
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-05-2008, 11:16 AM
  3. Initializing property object from a file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-29-2007, 05:55 PM
  4. Property File
    By Peter in forum JDBC
    Replies: 2
    Last Post: 07-04-2007, 04:48 PM
  5. log4j property file in my application
    By Peter in forum Advanced Java
    Replies: 3
    Last Post: 06-14-2007, 04:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •