Help on properties file

I am writing following code to read parameters from properties file (using java.util.properties) but it does not give any output. Please help ASAP.
CODE::
FileInputStream propFile = new FileInputStream("cont.properties");
          String dbUrl = "";
Properties props = new Properties();
props.load(propFile);
     props.getProperty("DatabaseUrl",dbUrl);
     System.out.println("DatabaseUrl = " + dbUrl);

I am finding one probelm.
it seems your property file contents is
dbUrl="1.2.3.4"; but it should be
DatabaseUrl="1.2.3.4";
Try this out.
Code is :
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class Test {
     public Test() {
     public static void main(String args[])
          try {
               FileInputStream fis = new FileInputStream("temp.prop");
               String dbUrl = "";
               Properties prop = new Properties();
               prop.load(fis);
               dbUrl = prop.getProperty("DatabaseUrl",dbUrl);
               System.out.println("DatabaseUrl="+dbUrl);
          } catch (FileNotFoundException e) {
               System.out.println("file not found");
          } catch (IOException e) {
               System.out.println("ioexception");

Similar Messages

  • PLEASE HELP. How do you access properties files in WEB-INF  and classes directory

    We have a war file that needs to access properties files that are in the WEB-INF directory
    of the war file. We also need to load one of the properties files from the classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjar and a
    war and the libraries both the ejbjar (with a manifest setting the classpath ) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path "WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO properties files
    have been extracted into their appropriate places ( not even those we throw into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves

    The file doesn't have to be extracted from the war. For example, you can place
    test.properties into your app WEB-INF and write a simple JSP to see how it
    works:
    <%
    InputStream in = application.getResourceAsStream("/WEB-INF/test.properties");
    %>
    It will return you a zip inputstream if you deployed your application as a .war.
    Christian Hargraves <[email protected]> wrote:
    I try this, but I get a NullPointerException. The file never actually gets extracted
    from the war. Under tomcat and resin this works great ( that's why I am having all
    of the trouble i am having ), but there are absolutely no properties files in the
    extracted directories for WebLogic deploys. only:
    WEB-INF/some_tmp_dir/WEB-INF/lib
    and then some dynamically generated jor file with all of the classes that would normally
    go in WEB-INF/classes ( all except the properties, of course, which are no where
    to be found. ).
    There has to be some kind of setting I am missing. Please don't make me seperate
    these properties files from the war/ear and then put the path to these properties
    files in the CLASSPATH, changing one step to three steps to deploy!!
    I have found a documented bug where you can't even put the properties files in a
    jar file and that bug will never be fixed for WebLogic 6.1.
    "Dimitri I. Rakitine" <[email protected]> wrote:
    To access files in WEB-INF you can use ServletContext.getResourceXXX("/WEB-INF/filename")
    Christian Hargraves <[email protected]> wrote:
    We have a war file that needs to access properties files that are in theWEB-INF directory
    of the war file. We also need to load one of the properties files fromthe classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjarand a
    war and the libraries both the ejbjar (with a manifest setting the classpath) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path"WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO propertiesfiles
    have been extracted into their appropriate places ( not even those wethrow into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves--
    Dimitri
    Dimitri

  • Help: Servlet can't read from properties file

    I am working on a web application running in Tomcat on Linux.My java source file reads some parameters from a properties file (data.properties)in the same directory. This works well in a simple application. However, if it is used in the Tomcat environment, it can't be read by a servlet file (LoginServlet.java). I put both the "LoginServlet.class" and "data.properties" in the following directory: /webapps/myapp/WEB-INF/classes. When I run the web application in Tomcat, the error is "data.properties not found". What is the problem? Do I need to modify my "web.xml" and/or Tomcat's "server.xml"? If so, how to modify them?
    This web application contains a lot of serlets. So I don't want to hardcode the parameters into the servlet codes.
    Any info will be appreciated. Thanks in advance!:)

    Putting the properties file in webapps/myapp may or may not help.
    My assumption is that you are trying to open the file by brute force, with something like
    InputStream propis = new FileInputStream ("data.properties");
    Properties props = new Properties ( );
    props.load (propis);
    What you want is to have the class loader find a file in the same place as the class file, and give you back an input stream reading from that file, which you can then pass to the Properties.load(InputStream) method. This is called a "resource," and the way to do it is:
    InputStream propis = getServletContext().getResourceAsStream("data.properties");
    // remaining code as above
    This will cause the class loader for the servlet context (a/k/a the Web application) to find the file in the same manner as it might find a class, but instead of treating it as compiled JVM code, and loading it, it simply passes you back an InputStream from which you do whatever you want.
    Cheers!
    Jerry Oberle
    perl -e 'printf "mailto%cg%s%cearthlink%cnet\n", 58, "oberle", 64, 46;'

  • Help with localization of a unicode .properties file

    Hi everyone, this is my first time posting anything.  I've googled like crazy but can't find an answer but if this is a repeat just forward me on along to the right spot!
    I'm using Flex Builder 3 for this project.
    We have several .properties files set up that we're converting to Russian.  I have the file set as UTF-8 encoding.  I use the mxmlc command to convert this to a SWF just like we do for our other languages.
    %flex_location%\mxmlc -locale=ru_RU -source-path=%viewMap_resource_sourcePath%\locale\{locale} -include-
    resource-bundles=collections,containers,controls,core,effects,skins,styles,ViewMapBundleSt ringResources
    -output %onefourtwo_loc%\core\framework\NxFramework\bin-
    debug\locale\strings\ViewMapBundleStringResources_ru_RU.swf
    In the code, I call something along the lines of:
    toolBar.title = ResourceManager.getInstance().getString(
    'ViewMapBundleStringResources', 'VIEW_SELECT_TOOLBAR_TITLE');
    this works for every other language, but none of our other languages are Unicode.  In this case, I get null back as the title.
    Any idea what could be going on here?  It seems like something is lost in the conversion from the properties file to a swf.  Like maybe I need to set the encoding somewhere else?  I've run the copylocale command so I have a russian folder in my flex folders, I'm generating the russian swf file and it has a decent size to it, comparable to the English version, just a little bigger.  I have Russian set as my locale, and my browser is displaying russian for sites like Google.  I'm running firefox although we support IE as well.
    Any advice would be helpful, we've been banging our heads on this one for a while!

    We actually got this working just in case any one else runs into this, I had it ENCODED to UTF-8, we actually needed to CONVERT it to UTF-8.  We did this through notepad++ and recompiled and everything is working fine now.

  • Need help for how to putting arabic content in java properties file

    Hi all,
    we have to support arabic in Java application.
    For that we are using java propeties file where key and value pair is used.
    In the Microsoft excel sheet arabic content is coming properly from right to left direction.
    When same thing is copied and paste in java properties file contents direction is reversed that is it is coming from left to right as in english.
    Please help how to put the arabic contents in propeties file
    Regards
    Vidya

    So in terms discussion.
    First I would suggest that you get a hex editor and validate exactly what is in the properties file. It appears to me that you are using one or more editors that are adjusting the display for you and thus that makes it hard to determine where the problem is. A hex editor should not adjust the display. Although even then you might want to right a simple java app and have it read bytes and print them just to validate that the hex editor isn't doing something.
    Only after you are exactly sure how the bytes appear in the file then proceed with other steps.
    For the java GUI only test the following.
    1. Properties file has it left to right then the java GUI displays it correctly right to left or not?
    2. Properties file has it right to left then the java GUI displays it correctly right to left or not?
    Myself I would expect that 2 should be the correct way to implement this. However that is dependent upon you correctly invoking the api as well. So if 2 is not working then you might want to look at the api. It might also have something to do with GUI display properties (of which I know even less.)

  • Which font.properties file to use- please help

    I am working on an application for accepting hindi text as input.Please help me in following matter-
    1. I have several font.properties file on my application server machine. Also some jre have font.propeties file. Which file should I change so that my forms 6i deployed on this application server can accept hindi font insatlled on application server machine.
    2. If I need to change my Jinititor , where should i make changes.
    Please help

    you have asked so many questions about hindi text, etc... and nobody could help you. Please contact the support and open an ITAR at metalink.oracle.com. They should help you.

  • Properties File - need some help

    hello, Im trying to figure out how to work with the Properties class. I think it can handle what i'm trying to accomplish. Maybe someone can point me in the direction of some rookie material to read. But anyway heres my dilemma. I need to create some form of structured message that can be saved (properties file), but i don't know how to structure it in the way specified.
    For example, say the message has 3 fields: ID(unsigned int), TIME(unsigned long int), and SIZE(unsigned int)
    I want ID to take up the first 2-bytes of the message, TIME to take the next 4, and SIZE have the remaing 4. Whats the best way to create this? I'm new to this stuff, and looking for some direction...i don't know where to start

    Take a look at the API docs for java.io.DataOutputStream and java.io.DataInputStream. If you are serializing these to the filesystem, you will want to wrap a java.io.FileOutputStream and java.io.FileInputStream with the appropriate data stream type.
    - Saish

  • ResourceBundle, Properties file ...syntax...HELP PLEASE

    Would someone please tell me how to correctly write a StringArray with key value pair in a properties file?
    Example:
    button.labels="Mrc","DataExtraction","ScheduleProcessing"
    button.Actions=mrc/data/schedule
    button.ImageIcons=FTIlittle.gif,FTIlittle.gif,FTIlittle.gif
    these are the ways I have tried...
    here is the code snippet:
    buttonLabels = resources.getStringArray("button.labels");
    buttonActions = resources.getStringArray("button.Actions[]");
    buttonImageIcons = resources.getStringArray("button.ImageIcons[]");
    I keep getting the error saying that my 'array' in the .properties file is not an array.
    How do I do this...
    Thanks in advance!

    Hello and Welcome to Apple Discussions. 
    Apple advise to use the Disk Utility if possible rather than fsck in 10.4.
    Boot from your Tiger install DVD.
    Don't run the installer but rather choose Disk Utility from the menu bar. In Disk Utility select Macintosh HD on the left hand pane and then click "Repair Disk" and "Repair Disk Permissions".
    Quit Disk Utility and exit the Installer.
    Let us know how you get on.
    mrtotes

  • Need some help in deployement.properties file

    Hi,
    I am doing installation using java web start and calling my own code for uninstallation purpose.Recently I came to know by changing the entry in deployment.properties file we can get the uninstallation link.
    By default the
    deployment.javaws.uninstall.shortcut = false
    in deployment.properties file.
    I need to make this entry as true
    deployment.javaws.uninstall.shortcut = true
    in deployment.properties during installation time.
    how to make this entry as true with out manual change in the properties file.
    Could you please let me know the same.
    Thanks,
    Sarayu.

    Why do you want to change function, if things already work fine?
    There's no point to do so.
    Anyway, I attach a screenshot of write to text file that do pretty much the same thing, but I'm not going to modify your code, unless you've a very good reason to modify your code.
    Attachments:
    da.png ‏31 KB

  • Help: why I cannot find the weblogic.mycluster.properties file

    When I first config the cluster. While Setting up the weblogic.properties
              Files, Open and read the cluster properties file (installed by default as
              weblogic/mycluster). Any properties set in the cluster properties file will
              override the same properties that were set from the global properties file.
              But I cannot find this file, Also I copy the weblogic.properties to
              weblogic.mycluster.properties,Also,I cannot find the
              weblogic.cluster.enable=true,etc.
              thanks
              

    It is required to put it in command line.
              Cheers - Wei
              Atish Ray <[email protected]> wrote in message
              news:[email protected]...
              > What happens if I set this property thru the properties file ? It still
              > works. Is there a known problem on this ?
              >
              >
              >
              > Wei Guan wrote in message <[email protected]>...
              > >Yes, the default cluster name is mycluster.
              > >
              > >Create an directory named 'mycluster' under your weblogic home, copy
              > >weblogic.properties to mycluster/weblogic.properties will do the trick.
              > >
              > >weblogic.cluster.enable=true has to be set via command-line. That is, add
              > >'-Dweblogic.cluster.enable=true' in your startup script.
              > >
              > >--
              > >Cheers - Wei
              > >
              > >
              > >
              > >hhb <[email protected]> wrote in message
              > >news:[email protected]...
              > >> When I first config the cluster. While Setting up the
              weblogic.properties
              > >> Files, Open and read the cluster properties file (installed by default
              as
              > >> weblogic/mycluster). Any properties set in the cluster properties file
              > >will
              > >> override the same properties that were set from the global properties
              > >file.
              > >> But I cannot find this file, Also I copy the weblogic.properties to
              > >> weblogic.mycluster.properties,Also,I cannot find the
              > >> weblogic.cluster.enable=true,etc.
              > >>
              > >> thanks
              > >>
              > >>
              > >>
              > >
              > >
              >
              >
              

  • Denied acces to Initialization properties file - help

    I am triing to load a properties file from a servlet. I added a JVM Option to find the properties file on the file system. I get the following error.
    java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)

    You mean you want a mapping between each directory and a class that will handle the new data?
    I would recommend that your "new file listener" peruses the upload directory looking for new files regularly and, when it finds one, calculates the directory it is in:
    eg, c:/ftp/dir1/myfile.xml gives dir1
    You can then use a Map to retrieve the class that should process this file.
    public interface ContentHandler
      public void handle(File file) throws ContentException;
    public class ContentHandlerManager
      private Map contentHandlerMap;
      public ContentHandlerManager() throws Exception
        Properties properties = new Properties();
        InputStream in = null;
        try
          in = getClass().getResourceAsStream("content-handler-manager.properties");
          properties.load(in);
        finally
          in.close();
        for(Enumeration e = properties.propertyNames(); e.hasMoreElements(); )
          String dir = (String)e.nextElement();
          String className = properties.getProperty(dir);
          ContentHandler contentHandler = (ContentHandler)Class.forName(className).newInstance();
          contentHandlerMap.put(dir, contentHandler);
      public ContentHandler getContentHandler(String directory)
        return (ContentHandler)contentHandlerMap.get(directory);
    }content-handler-manager.properties:
    # mapping from directory name to class name
    dir1=com.me.content.ContentHandler1
    dir2=com.me.content.ContentHandler2Hopefully some of this is clear.

  • Error reading properties file upon deployment

    hi. i'm still relatively new with regards to the Java programming language. in any case... i am developing a simple project wherein the application has to make a database connection to a server. the application is finished already however.. i am having problems deploying it.
    my project has a "resources" package containing the file "config.properties" which contains various information (connection details among others). correct me if im doing something wrong, but in deploying in, i copied the "dist" folder of my compiled code and then tried to run the java exe independently which resulted in an error. i already tried copying the "config.properties" file to the dist folder and even creating a "resources\config.properties" file but it still results in an error. could you please help me figure out how to deploy the application with the properties file. the code i used in referencing my .properties file is as follows:
    Properties configFile = new Properties();
                configFile.load(this.getClass().getClassLoader().getResourceAsStream("Resources\\config.properties"));
                String username = configFile.getProperty("username");
                String password = configFile.getProperty("password");
                String url = configFile.getProperty("url");
                String dbtype = configFile.getProperty("dbtype");
                Class.forName(dbtype);
                conn = DriverManager.getConnection(url, username, password); thanks in advance. ^^

    thank for the help mangst. i guess the IO approach is also applicable ^^; i changed my code to:
    configFile.load( new FileInputStream( ".\\resources\\config.properties" ) );but i had a little trouble in debugging it since it starts the file search from the main project directory. however it works fine upon deployment. ^^; thanks again.
    Edited by: xnofate on Sep 23, 2008 6:21 PM

  • Error reading Properties file

    I have a main method which i am using to call a servlet located in the same Development Component. Until recently i had the servlet location hard coded and it was working without issues. Now i decided to make the location configurable. For this i created an sap.application.global.properties file in the EAR DC which contains the WAR of this DC.
    The contents of the above file are as follows:
    SAP application properties
    SERVLET.LOCATION=http://<server-name>/ControllerServlet/servlet/com.nike.xapps.eqptsp.swem.controller.ControllerServlet
    The code i am using in the main method to call this properties file and access the property is as follows:
    Context ctx = new InitialContext();
    ApplicationConfigHandlerFactory cfgHdlr = (ApplicationConfigHandlerFactory)ctx.lookup("ApplicationConfiguration");          
    Properties props = cfgHdlr.getApplicationProperties();
    String servlet = props.getProperty("SERVLET.LOCATION");
    contained in a try...catch block.
    On dubugging i get a NoInitialContextException repeatedly in the statement where the lookup is performed.
    These are all the additions i have made for reading this properties file. Does anyone know if there is anything more that needs to be done for this to work.
    Thanks,
    Murtaza.

    thank for the help mangst. i guess the IO approach is also applicable ^^; i changed my code to:
    configFile.load( new FileInputStream( ".\\resources\\config.properties" ) );but i had a little trouble in debugging it since it starts the file search from the main project directory. however it works fine upon deployment. ^^; thanks again.
    Edited by: xnofate on Sep 23, 2008 6:21 PM

  • Reading values from properties file

    Hi All,
    I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
    Please help me in achieving this.
    Thanks,
    laxmi

    Hi All,
    I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
    Please help me in achieving this.
    Thanks,
    laxmi

  • How do I read a properties file in WEB-INF without hard-coding a path?

    Hello,
    How do I read a properties file in WEB-INF without hard-coding a path?
    I tried:
    Properties properties = new Properties();
    properties.load(new FileInputStream("db.properties"));
    driver = properties.getProperty("driver");
    but it cannot find the db.properties file.
    Thanks for the help.
    Frank

    Don't use a File to read those properties.
    Better to use the servlet context and
    getResourceAsStream() method to get the InputStream.
    It'll look for any file in the CLASSPATH. If you put
    that properties file in the WEB-INF/classes directory
    you'll have no problems, even if you deploy with a
    WAR file.Completely agree with this approach. Just have to mention the following for completeness
    according to the API,
    "This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet containers to make a resource available to a servlet from any location, without using a class loader. "
    So using this method, the resource can be anywhere under your web context, not just in the classpath.
    Cheers,
    evnafets

Maybe you are looking for

  • XML publisher report with a template file missing

    I get the following error Active template file not found in the template definition <TEMPLATE_NAME> for date <EFFDT>. (235,2515) PSXP_RPTDEFNMANAGER.TemplateDefn.OnExecute Name:GetActiveTemplateFile PCPC:15872 Statement:346 but in Reporting Tools > X

  • Using a BitSet object

    Hello ! I would like to store into MySQL a BitSet object. I am able to only use a string to do that :BitSet subBS = new BitSet(); String strSubSet = ""; subBS = Fingerprinter.getFingerprint(mol, 2048, 6); strSubSet = subBS.toString();This string coul

  • Problem in creation of  Personnel action

    Hi Experts, as per the requirement,we have maintaied operation INS for org assignment Infotype for action International assignement. We have a requirement to have the new cost center for this new action. But the cost center fiels id greyed out.Also i

  • Is it possible to create a Photo Gallery DVD with downloadable content?

    I am looking for a way to create a photo gallery, distribute it via DVD, and have the end user be able to download the photos from within the photo gallery. This would function exactly like the iPhoto web galleries, but would be distributed on DVD ra

  • VPD 9i

    Hi all! I have a problem and I would like to get your oppinion. The customer wants implement VPD. The database is Oracle 9i (9.2.0.7) on RHEL4AS Server. Initially, this step was included in Database Migration to Oracle 10g, but, the application runs