Problem in loading a Properties File

Following is my program which is actually reading a Properties file from a specific location and saving it latter. The program is able to save the Properties file but gives NullPointerException while reading it back.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import com.server.config.ConfigurationException;
import com.server.config.SimpleNetworkConfigurationManager;
public class Test {
     private static final Properties DEFAULT_CONFIGURATION;
     private static final String CONFIGURATION_FILE = "config/server_config.cfg";
     protected Properties m_config;
     static {
          DEFAULT_CONFIGURATION = new Properties();
          DEFAULT_CONFIGURATION.setProperty("ServerName", "Utility Server");
          DEFAULT_CONFIGURATION.setProperty("Host", "localhost");
          DEFAULT_CONFIGURATION.setProperty("Port", "1100");
     public Test(){
          try {
               loadConfiguration();
          } catch (ConfigurationException e) {
               //TODO: Log error message
               System.out.println("Could not load Configuration; Reason: "+e.getMessage());
               this.m_config = new Properties();
               this.m_config.putAll(DEFAULT_CONFIGURATION);
     public Map getAllConfigurationParameters() {
          return m_config;
     public Set getConfigurationKeys() {
          return m_config.keySet();
     public Object getValue(String configurationParameter) {
          return m_config.getProperty(configurationParameter);
     public void loadConfiguration() throws ConfigurationException{
          try {
               this.m_config.load(new FileInputStream(CONFIGURATION_FILE));
          } catch (FileNotFoundException e) {
               throw new ConfigurationException(e);
          } catch (IOException e) {
               throw new ConfigurationException(e);
     public void saveConfiguration() throws ConfigurationException {
          FileOutputStream fos = null;
          try {
               File file = new File(CONFIGURATION_FILE);
               file.createNewFile();
               fos = new FileOutputStream(file);
               this.m_config.store(fos,"Utility Server Configuration");
          } catch (FileNotFoundException e) {
               throw new ConfigurationException(e);
          } catch (IOException e) {
               throw new ConfigurationException(e);
          }finally{
               if (fos!=null){
                    try {
                         fos.close();
                    } catch (IOException e) {
                         //ignore
                    fos = null;
     public void setConfigurationParameters(Properties configurationParameters) {
          this.m_config = new Properties(configurationParameters);
     public String setConfigurationParameter(String param, String value) {
          return (String)this.m_config.setProperty(param, value);
     public static void main(String[] args) {
          Test configManager = new Test();
          try {
               configManager.saveConfiguration();
          } catch (ConfigurationException e) {
               e.printStackTrace();
}The Exception is as follows:
Exception in thread "main" java.lang.NullPointerException
     at Test.loadConfiguration(Test.java:52)
     at Test.<init>(Test.java:29)
     at Test.main(Test.java:92)
Please help me. I am unable to understand why is it happening. May be that I am doing some silly mistake.

dhirendra_logicon wrote:
The Exception is as follows:
Exception in thread "main" java.lang.NullPointerException
     at Test.loadConfiguration(Test.java:52)
     at Test.<init>(Test.java:29)
     at Test.main(Test.java:92)
Please help me. I am unable to understand why is it happening. May be that I am doing some silly mistake.Well, obviously, m_config is null. You cannot call a method on a null value.

Similar Messages

  • How to load a properties file?

    Hello Everyone,
    We are experiencing difficulties when trying to load a properties file from a directory other then the one where the servlet is located. We are using the following code for this purpose:
    private final String PROP_FILE_NAME = "my.properties";
    Properties props = new Properties();
    try {
    props.load(getClass().getResourceAsStream(codeBase + PROP_FILE_NAME));
    } catch(IOException e) {
    //handle error ...
    where codeBase is either physical directory path to the properties file or the URL. In either case we get a NullPointer exception which means that file is not found. But when we copy the properties file into the same directory where the servlet resides, everything works fine.
    Does anybody have an idea as to how to resolve our problem?
    Any help will be greatly appreciated!
    Thanks in advance!
    Y.M.

    URLs try to address this issue for cross-platform file reference.
    I'd try doing something like:
    URL u = new URL(codeBase + PROP_FILE_NAME);
    props.load(getClass().getResourceAsStream(u));
    Regards,
    Eric

  • How to load a .properties file by giving relative path in a JSP file.

    Hey guys,
    I'm trying to load a .properties file in a JSP using relative path...
    It is not taking the properties file..
    What is the problem...?
    Any solution..?
    Thanks a lot.

    Yes I tried that also.
    Your path was something like this ?
    http://localhost:8080/Database/a.properties ?
    Whether this path will change after client installation ? if no then what's the problem ?
    For client side installation how you are going to set your conf directory for your application ?
    You are not going to give client installation page ?which will have all the values to be set like conf path. database,user name(s),log folder,temp folder etc ? Why you are keeping everything on server ?
    Check if this is useful,
    String context = request.getContextPath();
    String rmtAdd = request.getRemoteAddr();
    String host = request.getRemoteHost();
    out.println("http://"+rmtAdd+context+"<BR>");
    out.println("http://"+host+context);
    "http://"+rmtAdd+context
    Edited by: kanad on Jan 12, 2008 1:29 PM

  • How do I load a properties file that is in the same package?

    I have the following package:
    com.company.ldap
    In the package I have:
    main.java
    settings.properties
    I want to load the values in the settings.properties file in code, such as:
    propertiesFile = "settings.properties";
            try {
                properties.load(new FileInputStream(new File(propertiesFile)));
            } catch (IOException e) {
                ... error logging logic ...
            }I keep returning "The system cannot find the file specified".
    How do I properly load a properties file in a class file within the same package?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Put the file in the classpath (such as in the parent directory of com/company/ldap). Then obtain an input stream to that file like this:
    InputStream stream = getClass().getResourceAsStream("/settings.properties");
    Then use that stream in the properties.load method. Remember to close the stream as well.

  • Websphere is not loading new properties file

    I am using Websphere Application Server 5.1 on WindowsXP.
    My application is on Struts. I create a war file and deploy it.
    I am getting all the text displayed from ApplicationResources.properites file.
    I changed some key-values in that file..but the websphere is loading the page with old values..
    I thought the problem could be with browser cache..I changed the JSP content to check if it loads the new jsp..It is loading the new jsp..(so the problem is not with cache)but old properties file..
    I uninstalled my application and reinstalled it..stilll it did not work..
    I checked the path "C:\Program Files\WebSphere\AppServer\installedApps\PC560\WMOS_war.ear\WMOS.war\WEB-INF\classes" where my war is getting extracted...
    (so my latest propeties file is available to websphere)
    it is showing the new properties file..but if i see the 'view source' of the page..it is showing old values..
    Is it some kind of optimization of websphere? If it is so, where to change it?
    Thanks

    If that doesn't work, try repackaging your application into a new WAR file, with the new property files, and redeploy it. WebSphere tries to be "clever" and caches/copies files from your application into another folder when you deploy it, and will not look at these files in your application's folder within the "installedApps" folder. I learned this lesson the hard way, when I wasted days trying to understand why WebSphere wasn't recognizing changes made to my web.xml file.

  • Problem while loading a jar file into database

    Hi All,
    We are using Oracle 8.1.5 in Solaris. When I try to load a jar file into the database by using loadjava it gives the following error
    Error while processing jar cryptix32.jar
    Exception java.io.IOException: Load Java is unable to handle compressed entries: cryptix/provider/Cryptix.class
    loadjava: 1 errors
    Can anybody suggest anything to overcome this. Thanks in advance.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by John Emmer ([email protected]):
    I presume you've tried creating the jar w/o compressing it? If not, and even if you didn't create the jar, then first unpack the jar into a directory and re-jar it without using compression.<HR></BLOCKQUOTE>
    Hi John,
    Thanks for your help. I unpacked the jar and rhen re-jared it with -0 (uncompress ) option. The above error is gone. But I am getting another problem. I am getting the following error for all the classes except the property files.
    Error while resolving class cryptix/cryptix/provider/cipher/Rijndael
    ORA-04043: object cryptix/cryptix/provider/cipher/Rijndael does not exist
    But the class is there in the jar. I am able to load single individual classes. Can anybody help me in this matter. Thanks in advance.

  • Problem in loading few jsp files

    Hi,
    I am facing problem in loading very few jsp pages. The situation is something like this.
    Server: WebSphere
    I have a top frame and bottom frame.
    When the user keep on clicking the same link in the top frame, not giving time to get loaded in bottom frame,
    on the server the error "Servlet Error: Connection reset by peer: socket write error: java.net.SocketException: Connection reset by peer: socket write error" was coming.
    My bother is not on the server-side. but on the client side.
    On the client side, the html of two requests are getting overlapped and displaying(see at the end for sample output of html). In this HTML, if you observe, you can find the line "Error 500: Connection reset by peer: socket write error
    ". Above to this is the half-content of the previous request and bellow is the actual page need to be loaded. And the output was a merge of actual page with the code of the previous request.
    Is it the problem of Websphere or coding?
    Can you help me resolving this problem?
    thanks
    naveen
    Output HTML (for example):
         Contract Name:</td>
         <td class="Label" ><input type="text" id="contractName"
    size="25" maxlength = "100"></td>
         <td class="Label" >Owner:</td>
         <td class="Label" colspan="2"><select id="owner" class="Label"
    size="1" style="WIDTH:200px">
         <option value="_______________">_____________</option>
         </select></td>
                   </td>
    Error 500: Connection reset by peer: socket write error
    <html>
    <head>
    <title> welcome </title>
    <link rel="STYLESHEET" type="text/css" href="Scripts/SSheet.css">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <!-- This .js script files contains all components, which is used -->
    .... and so on
    </html>

    Hi
    I have Observed that "java.net.SocketException: Connection reset by peer" is caused due to manual malfunction performed by the user in the browser like sending multiple request to the server stopping, moving forward, moving backward when a request is placed to the server and waiting for it to get it done.
    More clearly if the User Selected an option from the browser and send a request to the server and followed by sending another request immediately to the server and by this time Server is processed the first request and is started writing the result to the JSP/Browser (Same client), by this time the 2nd reqest from the same Browser/Client is interrupted the first one and ohhhhhhh..... problem , you got an error "java.net.SocketException: Connection reset by peer".
    If any one could figure out more Please update me too appreciate !
    [email protected]
    Sr. Software Architect

  • How to load a Properties file : Very URGENT

    I have properties file ie., SQLProperties.properties
    SQLProperties.properties
    logdetails = SELECT USERNAME AND PASSWORD FROM USER_TBL
    I want to load this file .
    I used like this
    public static Properties prop = null;
    strKey ="logdetails";
    FileInputStream fis = new FileInputStream("SQLProperties.properties");
    prop.load(fis);    // Since load parameter is file input stream
    prop.getProperty(strKey);But it is coming error while loading

    You did not initialize prop.
    //public static Properties prop = null;
    public static Properties prop = new  Properties ();
    strKey ="logdetails";
    FileInputStream fis = new FileInputStream("SQLProperties.properties");
    prop.load(fis);    // Since load parameter is file input stream
    prop.getProperty(strKey);
    [/prop]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem with placing of properties file

    Hi all,
    Iam using a properties file.
    From a jsp, Iam reading the property file.....
    Its giving FileNotFoundException....
    I hope its problem with placing of my properties file...
    I placed the properties file in WEB-INF/classes..folder.....
    But still iam getting the FileNotFoundException...
    PLz tell me where exactly should I place my properties file...
    Thanks ....

    first rule of using a forum: read recent topics !
    http://forum.java.sun.com/thread.jspa?threadID=668488&tstart=0

  • Problem with loading Danish dictionaries files.

    Hi,
    I want use Danish spell check for my project and when my app start load
    spell check files I get exception. Files are here http://www.stavekontrolden.dk/main/top/index.php.
    Please tell me is thare any way to use Danish spell check in flex application?
    And alos I can't find Finnish spell check that I could use with flex.
    Is flex support Finnish spell check ?? If no will flex support it?
    Error decription:
    Main Thread (Suspended: Error: null cannot be parsed to a squiggly dictionary)
    Thanks,
    Vladimir

    As Ned said the problem might be with the file structure on the server. Other problems may be with spelling. You computer may not be case sensitive to the names of the .swf files that you are loading, but your server might. So, on your computer when you are testing, second.swf is the same as Second.swf, or even second.SWF. But, on the server each of these variations is seen as a different file. Another problem is that when you are loading files from the same computer in testing, those files are close and so they load very quickly from your computer. When the files have to travel from the server, there will likely be a measurable period of time before the file is ready to be shown. This is particularly problematic with video that is embedded into an .swf. The whole file will need to be downloaded and uncompressed before it is available to play. If you stream the video as an external file, you can shorten the wait considerably.

  • Problem when load more swf files work with xml files into my movie

    hi ;
    I have one flash file & more of swf files which work with xml files .
    when I load one swf file into my flash file  and remove it and load anther one on the same movieclip in my flash file it load the old swf file.
    when i load one on movieclip and remove it and load anther swf  on anther movieclip the file doesn`t work  and stoped.
    when test my flash file to load and remove swf files without xml file it work fine but when repleaced the swf files with other work with xml files the problem hapend.
    thanks;

    YOu should trace the names of the files that are being targeted for loading to see if they agree with what you expect.  If you want help with the coding you will need to show the code that is relevant to your problem (not all of it)

  • How to load Java properties file dynamically using weblogic server

    Hi,
    We are using Java properties file in Java code. Properties in java properties file are frequently modified. If I keep these properties file in project classpath or as part of war, I will have to redeploy application after each change.
    We are using Weblogic Server.
    Can you please suggest me how can this properties file be loaded at weblogic server startup. Then in that case, how to refer property file in Java code?
    What is the best practice for this?
    Thanks,
    Parshant

    Another alternative is, keep the property file in any pre-defined location. Write a class which reads the properties from the file and returns the one which is requested by caller and deploy this class. Whenever you have to change the properties just update the property file on server and next call to fetch the property should return the updated one.
    Downside of this approach is file I/O everytime. To overcome that you can actually "cache" the properties in a hashmap. Basically when any property if requested, first check the hashmap, if not found then only read from property file and also update in hash map. Next time same property will be returned from hash map itself. The hash map will be cleared at every server restart since its in the memory. You will also need to build a method to clear the hashmap when you update the values in the property file on server.
    This solution would be suitable for small size files and when network overhead of calling a DB needs to be avoided.

  • Best way to load messages - properties file or database?

    Hi Guys,
    I have a debate with my colleague about best way to load/keep GUI messages.
    As we known, all those messages are in properties file, web tier will handle the messages loading to GUI.
    However, my colleague suggested, we could save all the messages in a database table, when application starts up, it will load all the messages from database.
    Please help me figure out pros/cons for both ways? What's the best to deal with message loading?
    Thanks

    allemande wrote:
    Please help me figure out pros/cons for both ways?There is no big difference with regard to performance and memory use. Both are after all cached in memory at any way. I wouldn't worry about it.
    The biggest difference is in the maintainability and reusability. Propertiesfiles are just textbased files. You can just edit the messages using any text editor. It is only a bit harder to wrap it in a UI like thing, but you can achieve a lot using java.util.Properties API with its load() and store() methods. Another concern is that it cannot be used anymore if you switch from platform language (e.g. Java --> C# or so) without writing some custom tool to read Java style properties files at any way. Databases, on the other hand, require SQL knowledge or some UI tool to edit the contents. So you have to create a UI like thing at any way if you want to let someone with less knowledge edit the messages. This is more time consuming. But it can universally be used by any application/platform by just using SQL standard.

  • Problems with struts MessageResources.properties files

    hi,
    I am a newbie in using struts. I have the following resources.
    Resources:
    java:j2sdk1.4.X
    struts:1.2.4
    webserver:tomcat 5
    jsp:2.0
    servlets:2.4
    IDE:Ecilipse 3.0 IDE
    Problem: I have copied the struts_blank.war file into tomcat webapps dir. Inside Ecilipse I create a new project and import the struts_blank.war file into the project. I type the URL (http://localhost:8080/proj_struts/Welcome.do)and it works file. However if i create any formbeans or any other java classes, the MessageResources.properties file gets deleted from my classes folder in my dir. What am i doing wrong. Is there any plugin for struts for Ecilipse.
    Questions:
    to be specific, where should/which folder should these .properties files be located. Should they be in classes or src folder under WEBINF?. I have seen the entry in strutsconfig.xml file. All it has is the following element relating to .properties.
    Fixes tried:
    I tried copying the MessageResources.properties file into the sources folder
    but i am not sure how to configure the Eclipse so that it reads the .properties file file from src folder insted of classes. I am definately sure thisis a dumb sol..but i donno wht else to do....
    <!-- ======================================== Message Resources Definitions -->
    <message-resources parameter="MessageResources" />
    It doesnt even say where is it looking(which folder).....
    Could some one throw some light on this issue and guide me thru this ordeal
    Regards
    AK

    Problem: I have copied the struts_blank.war file into
    tomcat webapps dir. Inside Ecilipse I create a new
    project and import the struts_blank.war file into the
    project. I type the URL
    (http://localhost:8080/proj_struts/Welcome.do)and it
    works file. However if i create any formbeans or any
    other java classes, the MessageResources.properties
    file gets deleted from my classes folder in my dir.No idea why this should happen.
    What am i doing wrong. Is there any plugin for struts
    for Ecilipse. http://easystruts.sourceforge.net/
    Questions:
    to be specific, where should/which folder should
    these .properties files be located. Should they be in
    classes or src folder under WEBINF?. I have seen the
    entry in strutsconfig.xml file. All it has is the
    following element relating to .properties.WEB-INF/classes, if nothing is specified :)
    Fixes tried:
    I tried copying the MessageResources.properties file
    into the sources folder
    but i am not sure how to configure the Eclipse so
    that it reads the .properties file file from src
    folder insted of classes. I am definately sure thisis
    a dumb sol..but i donno wht else to do....This solution may not be so dumb after all. The only thing you missed out was that Eclipse doesn't copy any files other than classes. Maybe a custom Ant script would have done such a trick :)
    <!-- ======================================== Message
    Resources Definitions -->
    <message-resources parameter="MessageResources"
    ces" />
    It doesnt even say where is it looking(which
    folder).....As I said earlier, it's looking in WEB-INF/classes

  • Problem with loading a Sequence File - Limited Windows Account

    Dear Sirs,
    I have a problem and a very less time to fix it; so I'm asking for your kind help.
    I have a production PC, with a Debug Deploy License of TS 3.1 and LV 7.1; the operating system is Win XP SP2.
    No problem when I login the session with my Administrator Windows Account; on the contrary, when I try to login with a Limited Windows Account, I'm not able to load my Sequence File, and the text appearing is attached to this message.
    Someone can advise me a solution to quickly solve my problem?
    Thank you very much and Best Regards.
    Stefano 
    Attachments:
    TS_error_winXP_login_limited_account.jpg ‏224 KB

    Stefano,
    if you open files in TestStand, TestStand tracks this in different configuration files (for example for the "most recently used" list). Therefore, TestStand tries to save these changes in the ini-files. It seems to me, that the installationdirectory of TestStand is not permitted to be used for writing for your user login in Windows.
    So you have different solutions here, the simpliest being:
    Give your user the right to write files into the < TestStand >\-folder.
    hope this helps,
    Norbert B.Message Edited by Norbert B on 11-16-2006 07:28 AM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

Maybe you are looking for

  • Downloaded itunes update 9.1.. iphone is no longer recognized

    updated and installed the latest version of itunes the other day, and ever since my computer no longer recognizes my iphone. it does not show up in itunes, and it does not charge when plugged in. i have uninstalled and redownloaded itunes several tim

  • How to import songs AND all the data from iPod to iTunes?

    Hi, I am looking for a tool that can import more than just the music from iPod to iTunes. I have tried several apps to no avail. (many mentioned in another post here: http://discussions.apple.com/thread.jspa?threadID=1576568&tstart=15 ) I "upgraded t

  • Opening a webpage goes to previously open tab

    Hopefully the question title describes the issue Firefox must have done an update because for example I have a browers open with 10 tabs and then open a new tab to load google.com If one of the previous 10 tabs had google.com as a page I had loaded c

  • Verizon DSL - Frustrating Performance

    I've been using Verizon DSL for about 6 years now. For a while, service was sufficient, but for the last year I've had nothing but negative experiences with it. I've been experiencing slow speeds and frequent disconnects. I've called tech support num

  • Automate Batch feature - possible to maintain subfolder structure?

    Hi, I have some custom actions that I batch run regularly on a folder of images. The images are sometimes contained in subfolders. Photoshop has a checkbox in the Automate> Batch menu to "include subfolders" in the selection folder. Is there a way to