Results 1 to 8 of 8
  1. #1
    peiceonly is offline Member
    Join Date
    Mar 2007
    Posts
    41
    Rep Power
    0

    Default Reading a properties file

    Hi
    How can I read a properties file n java ?
    The file is named config.properties.
    Do we need additional jars for it ?
    Should I read it as output stream

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Java Code:
     // Read properties file.
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream("filename.properties"));
        } catch (IOException e) {
        }
        
        // Write properties file.
        try {
            properties.store(new FileOutputStream("filename.properties"), null);
        } catch (IOException e) {
        }

  3. #3
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Sometimes I get an error that my application cannot find this properties file. I have been having a lot of issues with this lately. Any clues why?

  4. #4
    levent Guest

    Default

    Sometimes I get an error that my application cannot find this properties file. I have been having a lot of issues with this lately. Any clues why?
    Are you giving correct path to properties file? If properties file is not in the current working directory, you should give correct path (e.g. c:/1.properties or /home/levent/1.properties) to the FileInputStream and FileOutputStream constructors.

  5. #5
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Here is the error I am getting:
    05/10/2007 10:12:58 [http-9090-Processor24]:med.tas.commons.util.Settings.loadSettingsFile()2 26 Cannot load settings file constants.conf; bad path supplied or file does not exist
    java.io.FileNotFoundException: C:\Documents%20and%20Settings\pp\workspace\Bar CodePrintingService\web\WEB-INF\classes\constants.conf (The system cannot find the path specified)
    But my file IS in the location that it mentions above. Why can it not find the path? Am running eclipse/tomcat.
    thanks

  6. #6
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Include a file such that there is no space between the folder names in the path like "Docments And Settings"

  7. #7
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default

    what if I want to read a property file from remote location?

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    If you have any questions, please ask it in a new thread. Thank you for your cooperation.

Similar Threads

  1. Reading a properties file using resource bundle.
    By rudrakanth in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 01:23 PM
  2. Taking input from Properties File
    By bugger in forum New To Java
    Replies: 4
    Last Post: 05-07-2008, 10:30 AM
  3. How to getvalue from properties file into JSP
    By jaga in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-04-2008, 09:00 AM
  4. Replies: 0
    Last Post: 01-30-2008, 10:56 AM
  5. doubt about language .properties file
    By tommy in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 03:38 PM

Posting Permissions

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