Explain What is Property Files ?

Hi,
I want to know what is Property files in java.What they exactly does?Pls. do provide a sample example for a better understanding.
Thanx,
m.ananthu

It's like an ini file. Maybe you have a ftp program and you want it to point to a different location depending on where you install the application, but you do not want to compile the application every time it changes.
ftplocation=sun.java.com
user=mlovern
password=mypassword
appname=Test App version 1.0

Similar Messages

  • Character '\' is lost when reading a String from a property file.

    Hi all,
    I have encrypted information inside a property file, but when loading properties in my program, the String object used to store the value is changed by the lost of all �\� characters
    # EIS password saved in the property file
    password=WPLqQE0DlVF8Sg\=\=
    #Value loaded in my String object
    WPLqQE0DlVF8Sg==
    Why is this happening? I use java.util.Properties java class to store and load my properties, and it is supposed to do it with the same encoding (ISO 8859-1).
    Please, can someone explain me why this happened and how to solve it?
    Best regards.

          public static void main(String[] args) throws IOException {
               OutputStream props = new FileOutputStream("test.properties");
               Properties p = new Properties();
               p.put("password", "pass=word#is!dumb");
               p.put("user", "    I am a Dummy");
               p.store(props, "Java forum demo props file");
               props.close();
               /* Properties file after store
                * user=\    I am a Dummy
                * password=pass\=word\#is\!dumb
               Properties post = new Properties();
               post.load(new FileInputStream("test.properties"));
               for(Iterator it = post.entrySet().iterator(); it.hasNext();)
                System.out.println(it.next());
                * After load from test.properties
                * user=    I am a Dummy
                * password=pass=word#is!dumb
          }Notice that the special chars are only in the file, not actually in the props. If you think otherwise, I don't know what to say. The \ is a special character that is used to escape other special chars, including itself. You can't create a string in java containing only one backslash, as java assumes the next char is being escaped. when you create a string in Java with one backslash, you have to have 2 backslashes. If you are storing data in the property file using something other than store, than you need to ensure that you are escaping all special charachters that the store method does
    ~Tim

  • How to use an equal sign as a part of the value in a property file

    say I have this line in a properties file:
    args = -Xms512m -Xmx512m -XX:MaxPermSize=256m
    obviously I can't use the (=) as is. What should I do to make it work?
    I tried to use \= and \:, but it doesn't work as well.
    thanks.

    A property file contains "key" lines or "key=value" lines the '=' character loses its special meaning after a key is read so you can use '=' characters in the 'value' part of a property.
    kind regards,
    Jos

  • Error while reading a property file from a war.

    Hi,
    I am trying to read a property file which is available in the properties folder.
    The piece of code that does this read is as follows.
    InputStream is = ClassLoader.getSystemResourceAsStream("codemap.properties");
    System.out.println("Reading file:"+is);
    properties.load(is);
    The "codemap.properties" file is available in the properties folder.
    Following is my directory structure in the war file
    sample.war
    |
    |
    WEB-INF
    |
    |
    classes
    |
    |
    properties
    |
    |______ codemap.properties
    Inside the war file I have WEB-INF and properties folder.
    Inside WEB-INF i have the classes folder which has the classes
    Inside the properties folder I have the codemap.properties file.
    I am using Jboss. In the class path I have ./properties
    I have also added this classpath in the manifest file.
    Problem: The piece of code that I have written to read the property file is not able to locate the file and this it returns null.
    I am not sure what i am missing here.
    If anyone there have any solutions please let me know.
    Thanks in Advance
    Balaji.

    I think you've to change this line
    InputStream is = ClassLoader.getSystemResourceAsStream("codemap.properties");with this.
    InputStream is = ClassLoader.getSystemResourceAsStream("properties/codemap.properties");it is unable to find the path you specified. by default it'll check the WEB-INF directory. so you've to give the relative path to it.
    Diablo

  • Can anyone explain what the other section section in the HDD usage description is for ? I recently used iphoto to send a mail and this "other "section inrease the usage by about 1GB....any ideas why ?

    Can anyone explain what the "other" (yellow colour) section in the HDD usage description is for and what it does.It is under the about this mac section and storage option?
    I recently used iphoto to send mail with photos attached and this "other" section increased by about 1GB. The mail size was around 900KB.....any ideas ?

    Shurig wrote:
    Thanks gor replying,,,this is my first time on this site.
    Any idea why the "other" continues to increase. I have just got got my mac so no new apps installed yet only been using it for mail and web browsing. I tried the iphoto mail last night and noticed the the "other" section had increased by 1GB which I thought was rather larger. Do you know what this setion actually does ?
    Also do you know if it is possible to delete the iphoto emails.
    All of your 'stuff' that is not Music Movies Apps Backups or Photos is in Other, that means all your emails, all your files etc, why don't you just leave well enough alone, this is not windows and doesn't need tinkering with,

  • Read a property file and store it in a hashmap

    Hi,
    I have tried to read a property file and store it in a hashmap. The property-names should be stored in keys and the property-values (after = symbol) in values of the hashmap. any ideas? Is it possible to do this?

    mandy2001ir wrote:
    yes, but I need the hashmap for another reason. Actually I'm trying to use the properties file to have a dynamic hachmap. I don't want to change the code anytime I want to put a value in the hashmap. therefor I write the "keys" and "values" in a property file and change the property file. That's the reasn why we have property files, isn't it?What's a "dynamic hashmap"? There's no other kind! Whenever someone starts bandying around the word "dynamic" in contexts like this, it usually means there's a simple solution to their problem, that they haven't yet considered, or mistakenly don't believe is applicable to them, because of this "unique" need for something "dynamic". Trust me, you just need to load the file using a Properties object, and you're done. Properties extends Hashtable, which is virtually the same thing as a HashMap. Properties does exactly what you want it to. it's the very reason the class exists
    Have you even looked at the javadoc for java.util.Properties yet? I'm betting not, because if you had, you'd know exactly what I meant. And since you haven't, I'm at a bit of a loss as to how you can so easily dismiss the class as useless, despite existing to do exactly what you need

  • Property file usage help please !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

    hi there
    i need some help on using property file, please. i have a package that contains many directories and classes. in one the directory, there is a property file: properties. and some of the classes need to access information in the file. how can i use ResourceBundle or Property objects to read the file? this is my guessing :
    //code....................................
    ResourceBundle.getBundle("D:\\tomc\\wowExchangeProject\\soaptest\\src\\com\\wowgao\\uddi\\db\\properties.properties").getString("implementation");
    and:
    //code....................................
    File f=new File( configFile );
    if( f.exists()) {
    Properties props=new Properties();
    props.load( new FileInputStream(f));
    DBClassName = props.getProperty("implementation");
    i must use absolute path for the file. what if i need to distribute the package on other machine that does not have D drive. how can change it so that i can deploy it on any machine? thanks

    hi there
    i need some help on using property file, please. i
    have a package that contains many directories and
    classes. in one the directory, there is a property
    file: properties. and some of the classes need to
    access information in the file. how can i use
    ResourceBundle or Property objects to read the file?
    this is my guessing :
    //code....................................
    ResourceBundle.getBundle("D:\\tomc\\wowExchangeProject\
    soaptest\\src\\com\\wowgao\\uddi\\db\\properties.proper
    ies").getString("implementation");
    and:
    //code....................................
    File f=new File( configFile );
    if( f.exists()) {
    Properties props=new Properties();
    props.load( new FileInputStream(f));
    DBClassName =
    ame = props.getProperty("implementation");
    i must use absolute path for the file. what if i need
    to distribute the package on other machine that does
    not have D drive. how can change it so that i can
    deploy it on any machine? thanksHi!
    Let�s say you have the following structure:
    - com/props/props.properties
    You can use any class inside the classloader that loaded this package to do the following:
    InputStrean in = <classname>.class.getResourceAsStream("/com/props/props.properties");
    Properties props = new Properties();
    props.load(in);
    Hope this can help you. Any doubts just ask!
    MSB

  • UTF-8 encoded property files with RessourceBundle

    Hello everybody!
    Is there a way to force RessourceBundle to use a specific kind of encoding for the property files I've defined?
    I plan to encode the property files for my application using UTF-8. This will avoid problems, when e.g. the labels for some buttons will get names in Spanish, German, Frensh etc..
    Problem: the class RessourceBundle seems to use an InputStream and not a Reader. Therefore I have problems forcing the encoding UTF-8 used in my property files.
    Is there any solution to this?
    Kind regards and thank's for your response,
    Marcus.

    Hi Marcus,
    You should be able to do what you're trying. Instead of backing your resource bundle with properties files, use a ListResourceBundle and back it with the corresponding class files. Create your *.java files in UTF8 and use the -encoding UTF8 argument to javac. Any *.java files you've previously created in ASCII will compile correctly using -encoding UTF8 (one of the nice features of UTF8).
    see here: http://java.sun.com/docs/books/tutorial/i18n/resbundle/list.html
    Also, see the following 1.4 Java docs for internationalization:
    start here: http://java.sun.com/j2se/1.4/docs/guide/intl/index.html
    and follow links, especially the link to the internationalization tutorial:
    http://java.sun.com/docs/books/tutorial/i18n/index.html
    to the encoding document:
    http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html
    and the link to the internationalization FAQ
    http://java.sun.com/j2se/1.4/docs/guide/intl/faq.html
    regards,
    Joe

  • How can we locate the property file and read from it in .js page?

    HI
    I am having an static html page where in the url is hardcoded,so i wanted to read it from a property file and which can be done by using .js files
    i wanted to know how to deal with property files in .js?
    Thankx

    I assume you know that Java and JavaScript only share a name and they are both programming languages but little else.
    You can load JavaScript in Java 6. However for questions on what the JavaScript should do I suggest you try a javascript forum.

  • Best practice for property file

    I am trying one small code which uses values from property file.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException
          InputStream inputStream = servletContext.getResourceAsStream(/WEB-INF/test.properties);
          PrintWriter out         = response.getWriter();
           Properties prop = new Properties();
           prop.load(inputStream);
           inputStream.close();
          String nameprop = prop.getProperty("name");
          out.println(nameprop);
       }I am getting the value from property file, It's perfectly ok as far as test code is concerned. Above will open the inputStream for each thread, which is not needed so i modified it and put in inside init() method. That is also working, i believe this will give me some better performance.
    But can i extend it further? I load property file at application level and all my servlets make use of it?
    What is normal practice to read property file to get good performance? I serached forum, i found some info there but could not figure out exactly how people are doing it.
    Thanks in advance,
    regards
    Manisha

    Thanks to all posters,
    As mentioned by duffymo, I tried some code which i tested on my m/c and working fine. But just want to confirm, what i understood and wrote is correct.
    I wrote 1st servlet to get the property file and store into servlet context, 2nd servlet is just to test it.
    1st Servlet:
    package common;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    public class TestPropertyfiles_1 extends HttpServlet
    public void init(ServletConfig config) throws ServletException
       super.init(config);
       try{
            String PF_PATH = "/WEB-INF/test.properties";
            Properties prop = new Properties();
                            InputStream inputStream = config.getServletContext().getResourceAsStream(PF_PATH);
           prop.load(inputStream);
           inputStream.close();
           getServletContext().setAttribute("pf", prop);
       }catch(Exception e){}
    public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException
            PrintWriter out         = response.getWriter();
            Properties tmpprop = (Properties) getServletContext().getAttribute("pf");
            String nameprop = tmpprop.getProperty("name");     
                out.println("name from property file" + nameprop);     
    }2nd servlet:
    package common;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    public class TestPropertyfiles_2 extends HttpServlet
         public void init(ServletConfig config) throws ServletException
            super.init(config);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException
            PrintWriter out         = response.getWriter();
            Properties tmpprop = (Properties) getServletContext().getAttribute("pf");
            String nameprop = tmpprop.getProperty("name");
                            out.println("name from property file - no 2" + nameprop);
    }This was initially giving problem if I access 2nd servlet first before accessing 1st servlet. I did some changes inside web.xml
    <servlet>
    <servlet-name>common.TestPropertyfiles_1</servlet-name>
    <servlet-class>common.TestPropertyfiles_1</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    And then all was ok.
    One thing came to my mind. I can have one common servlet just for all initialisation, this will not have any doGet/doPost.
    regards
    Manisha

  • What is this file

    I am in the process of moving pictures off my PC to my Mac. I am using a USB Memory Stick. Each time I move pictures a file also appears in the folder "thumbs.db" With an ICON View, its a gray box with the word 'exec' inside. Right clicking for info, I see the following response;
    Unix Executable File. I double click on it and get the msg, 'No application specified to open this document thumbs.db
    What is this file, can it be sent to trash or ???
    Thank You
    WM-300

    The purpose of the thumbs.db file is explained on this page; these files are safe to delete.
    (16272)

  • JSP Registry could not locate runtime property file

              At runtime, my JSP is throwing an exception claiming to be not able to find the property
              file. I have found the exact property file in the jar located on the server. I've
              tried extracting it and placing it in different places and adding the file and directory
              to the WebLogic classpath. I'm not sure what else to try.
              Here's the exception:
              Loading from CLASSPATH cat_test4_cat_pkg_Cat_pkgModule.properties
              java.lang.RuntimeException: JSP Registry could not locate runtime property file:
              cat_test4_cat_pkg_Cat_pkgModule.properties
              at java.lang.Throwable.fillInStackTrace(Native Method)
              at java.lang.Throwable.fillInStackTrace(Compiled Code)
              at java.lang.Throwable.<init>(Compiled Code)
              at java.lang.Exception.<init>(Compiled Code)
              Thanks.
              

    When you generate a webapp or use the JSP element wizard , a property file is created for you that contains some startup parameters. This file needs to be available in the classpath. This errors comes up becuase the file is not avalable in the classpath.

  • How to convert Property files into Java Objects.. help needed asap....

    Hi..
    I am currently working on Internationalization. I have created property files for the textual content and using PropertyResourceBundles. Now I want to use ListResourceBundles. So what I want to know is..
    How to convert Property files into Java Objects.. I think Orielly(in their book on Internationalization) has given an utitlity for doing this. But I did not get a chance to look into that. If anyone has come across this same issue, can you please help me and send the code sample on how to do this..
    TIA,
    CK

    Hi Mlk...
    Thanks for all your help and suggestions. I am currently working on a Utility Class that has to convert a properties file into an Object[][].
    This will be used in ListResourceBundle.
    wtfamidoing<i>[0] = currentKey ;
    wtfamidoing<i>[1] = currentValue ;I am getting a compilation error at these lines..(Syntax error)
    If you can help me.. I really appreciate that..
    TIA,
    CK

  • Can anyone explain what the 'other' storage consists of and how I can decrease the size please?

    Can anyone explain what the 'other' storage consists of and how I can decrease the size please?

    Welcome to Apple Support Communities
    "Other" refers to OS X files, caches, downloads, documents. See Other in this website > http://pondini.org/OSX/LionStorage.html
    I would not worry about Other because they contain files that you need, but if you want to decrease the size, start deleting downloads and documents

  • Bluetooth: can someone explain what you can do with it?

    On the iPhone, is bluetooth only for pairing with a BT headset? no data transferring/receiving whatsoever with a powerbook? if so, has Apple gone mad?
    thanks

    It is easier to explain what it cannot do.
    • it does not support OBEX file exchanges
    • it does not support DUN connections via Bluetooth to connect your computer through it to the internet
    • it does not synchronize contact, events or media files
    Support for synchronization and file transfer it available only via USB through iTunes 7.3 or later.

Maybe you are looking for

  • Program Modification

    hello experts I have the following ALV report, (ZBB Program) <b>Material Document Listing Report</b> Currently this  report let us  drill down to some transaction where we would see standard costs(Drill down fields are Customer and Mterial number) No

  • Lightroom to PS CS4

    I have two problems at the moment. Since upgrading to CS4 I cannot link to Bridge, the message is "Photoshop unable to find java script plug-in". I can open Bridge from the Applications folder but not from Photoshop. The other problem that has sudden

  • Solaris adapter: Error building user.

    Hello! We are using our IDM to manage users in Solaris Zones. This worked fine, but after moving some zones to a new system, the IDM says it does not find the users any more. When I do a "Accounts / Load from resource", I get the following error for

  • Where are iWeb backgrounds on my hard drive

    I just upgraded to iLife '08 and I like the darkroom backgrounds you can tile and would like to use it in a separate template, but I don't want to change the entire template to darkroom. Where on my hard drive did iLife store these templates so I can

  • Af:tree expand/collapse customization

    hi all, i have problem with af:tree expand and collapse. I want to expand only one node in each level. i mean let say i have 3 node in same level. i expand first one then i expand second node again. at that time, first one should be collapsed automat