Java
  Home arrow Java arrow Reading a Properties File for a Java Appli...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Reading a Properties File for a Java Application using NetBeans IDE
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2006-05-31

    Table of Contents:
  • Reading a Properties File for a Java Application using NetBeans IDE
  • How to get the current working folder (or where the current class file exists) in Java
  • Starting to develop a Java application using NetBeans IDE
  • Adding a properties file
  • Reading the connection string from the properties file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Reading a Properties File for a Java Application using NetBeans IDE


    (Page 1 of 5 )

    This article introduces you to a step-by-step process for developing Java (or JFC) based applications with Microsoft SQL Server as the database, using NetBeans IDE. It is the second in a series, and focuses on showing you how to read the properties file.
    A downloadable file for this article is available here.

    I already introduced you to the NetBeans IDE in my earlier article, "Developing Java Applications using NetBeans."  Even though that article is a fairly introductory piece, the next two articles concentrate on basics of JFC.  You can find those articles here and here.

    If you are new to NetBeans IDE, I strongly suggest you go through the previous articles first, before proceeding with this one.  If you are new to developing Microsoft SQL Server based Java applications, I suggest you go through another article of mine here

    How to get the current class name of the Java application being executed

    Before directly going into how you read the properties file (for the connection string), we need to have some "utility" methods which may be necessary in certain scenarios.  One of those utilities is the "CLASSNAME."  In this section, we shall discuss a small "utility" method for retrieving the current class name.

    Let us first go through the following code:

    public String getClassName()
       {
          String thisClassName;     

          //Build a string with executing class's name
          thisClassName = this.getClass().getName();
          thisClassName = thisClassName.substring
    (thisClassName.lastIndexOf(".") + 1,thisClassName.length());
          thisClassName += ".class";  //this is the name of the
    bytecode file that is executing     

          return thisClassName;
       }

    Within the above method, the following statement already retrieves the class name we want:

    thisClassName = this.getClass().getName();

    But, the above statement may also retrieve the package name (or other information).  So, the next statement extracts only the pure "class" name (by simply reading the class name after the final dot):

    thisClassName = thisClassName.substring(thisClassName.lastIndexOf
    (".") + 1,thisClassName.length());

    At this point, it should be more than enough.  Last but not least, I would also like to have the class name be turned to "class file name" (by simply adding the extension ".class" at the end).  The following statement does the same:

    thisClassName += ".class";  //this is the name of the bytecode
    file that is executing

    Once everything is ready, we return it to the calling function by issuing the following statement:

    return thisClassName;

    The next section will deal with retrieving the current folder where the class file exists.  If you are not interested, you can skip to the next section, but please be aware that I am using all the utility methods in this application to achieve what we require.

    More Java Articles
    More By Jagadish Chaterjee


       · Hello guys! You can read properties file in a simpler fashion using Java together...
       · ResourceBundle bundle =...
       · Your method getLocalDirName can be improved in three ways:1) you call...
     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek