Results 1 to 4 of 4
  1. #1
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default how to read properties file in java?

    I have properties file "myprop.properties" file in prop folder under my webcontent folder.

    now how can i read this file in my Java file ?

    I dont want to give the system path for the file (Ex: C://myapp/prop/myprop.properties)

    I have tried with

    final String BUNDLE_NAME = "/myapp/prop/myprop";

    It is throwing "Missing resource exception".


    Can anyone help me please ?
    Arun K R,Bangalore,India
    :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    If you are having a hard time getting the path to find the file, try this:
    Create many versions of the prop file and put them in all the possible folders that the code could look in. Put a unique content in each file. Then when the file is read, displaying that content will show you which file was read. Then you'll understand the path usage.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    836
    Rep Power
    6

    Default

    I think webcontent means servlet/jsp related solution.I think below items will work for you.

    1. Use ServletContext getResourceStream to load the file in this path /myapp/prop/myprop .

    2.Use the properties load method for loading the above retreived inputstream object so that you will get property file info as key value pairs.
    Last edited by RamyaSivakanth; 07-23-2010 at 01:18 PM.
    Ramya:cool:

  4. #4
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default

    Thank you for the reply.. I will try the same..
    Arun K R,Bangalore,India
    :)

Similar Threads

  1. jdbc (java.util.)Properties file
    By jon80 in forum JDBC
    Replies: 3
    Last Post: 04-05-2011, 07:55 AM
  2. help to read .pst file through java
    By umadas in forum Advanced Java
    Replies: 2
    Last Post: 12-19-2010, 04:32 AM
  3. Unable to access velocity.properties file from jar file
    By mjwoodford in forum New To Java
    Replies: 0
    Last Post: 10-09-2009, 01:46 PM
  4. Replies: 5
    Last Post: 01-20-2009, 09:08 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 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
  •