How to use a config file?

People,
i have a basic question. How to extract the contents from a ".config" file?
I have a config file with few sections and few global variables defined.
how to extract these data; or how to use this file?
a sample .config file, that i have is,
# global variables
pageTitle = "Main Menu"
bodyBgColor = #000000
tableBgColor = #000000
rowBgColor = #00ff00
[Customer]
pageTitle = "Customer Info"
[Login]
pageTitle = "Login"
focus = "username"
Intro = """This is a value that spans more
than one line. you must enclose
               it in triple quotes."""
# hidden section
[.Database]
host=my.domain.com
db=ADDRESSBOOK
user=php-user
pass=foobar
How would i extract these data; or how to utilize this file first of all?
- Kumar
[ [email protected] ]

Hi Kumar,
Instead of .config file you can use .properties file. Place the configuration part in that file. Use ResourceBundle class. This class have methods like getResourceString(String key) which reads the .properties file and returns a String as it's Value. I normally use the same. I have written one class for it. C if you can use it. The keys are case sensitive. initialize is a directory in which i am keeping my Config.properties file.
import java.util.*;
import java.text.*;
import java.net.*;
import javax.swing.*;
public class ReadConfig
public static ResourceBundle resources;
* This is responsible for getting data from Config.properties for setting properties externally.
static
try
resources = ResourceBundle.getBundle("initialize.Config", Locale.getDefault());
catch (MissingResourceException mre)
JOptionPane.showMessageDialog(new JFrame(), "initialize/Config.properties not found.\n Please report it to administrator.");
System.err.println("initialize/Config.properties not found");
System.exit(1);
}//static
public ReadConfig()
System.out.println(getResourceString("DatabaseName"));
System.out.println(getResourceString("JDBCDriver"));
System.out.println(getResourceString("DSN"));
System.out.println(getResourceString("ConnectionString"));
}//constructor
public String[] tokenize(String input)
Vector v = new Vector();
StringTokenizer t = new StringTokenizer(input);
String cmd[];
while (t.hasMoreTokens())
v.addElement(t.nextToken());
cmd = new String[v.size()];
for (int i = 0; i < cmd.length; i++)
cmd[i] = (String) v.elementAt(i);
return cmd;
* A method takes string as parameter and reference of ResourceBundle.
* It is used with <b>Resources Bundle</b> i.e. with .properties file.
* When value of particular string from .properties file has to retrive.
public String getResourceString(String nm, ResourceBundle resources)
String str;
try
str = resources.getString(nm);
catch (MissingResourceException mre)
str = null;
return str;
* A method takes string as parameter. It is used with <b>Resources Bundle
* </b> i.e. with .properties file. When value of particular string from .properties
* file has to retrive.
public static String getResourceString(String nm)
String str;
try
str = resources.getString(nm.trim());
catch (MissingResourceException mre)
str = null;
return str;
}//getResourceString(String nm)
* This method takes string as parameter and returns corresponding <b>URL</b>.
* If key is <b>null</b>, then will return <b>null</b>.
public URL getResource(String key)
String name = getResourceString(key);
if (name != null)
URL url = this.getClass().getResource(name);
return url;
     return null;
}//getResource(String key)
public static void main(String[] args)
new ReadConfig();
}//main
}//class
Hope this will be helpful to you.
Kind Regards
Sandeep

Similar Messages

  • How do I disable Autocomplete using the config files - NOT by using Options Privacy...

    Hi,
    I have around 300 computers around the country which need the Autocomplete feature turning off for forms.
    Obviously it wouldn't be practical to remote onto each machine and change the setting in Options > Privacy > Firefox Will... > Use custom settings for history > Remember search and form history - nor is it practical to use the about:config screen since the address and toolbars are disabled by default to prevent users from browsing to other pages they aren't meant to.
    I was wondering if there was a config file or a registry setting where I can change this setting in the backgorund, that way we can push the config files or a registry tweak out the all machines that would change this setting.
    Any help would be appreciated greatly.
    Dan

    I can see where those answers are going, there must be an easy way to do it using js config files or userChrome.css.though.
    I tried doing an entry in userChrome whereby it hides the autocomplete box by overriding the pages stylesheet but the entry only seemed to work on a per domain basis... however the site that the browsers will be using is an intranet and therefore each PC will have a different URL to go to - making it impractical for masses of machines. Not sure if this can be worked upon to apply to every site?

  • How to use multiple video files??

    hi all,
    i am using flex 4 ...
    now i have designed video player..
    i used single flv file for execution..
    how to use more flv files in tis program???
    i have included program also..
    can any one reply for this...
    thanks in advance...
    regards,
    saran r
    video.mxml:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()" height="700" >
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.core.UIComponent;
                import flash.events.NetStatusEvent;
                import flash.media.Video;
                import flash.net.NetConnection;
                import flash.net.NetStream;
                private var nc:NetConnection;
                private var stream:NetStream;
                public var videoDuration:Number;
                public var nsClient:Object = new Object();
                private var videoComp:Video = new Video();
                private var meta:Object = new Object();
                private var timer:Timer = new Timer(100);
                private var uiComp:UIComponent = new UIComponent();
                private function init():void
                    nc = new NetConnection();
                    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                    nc.connect("rtmp://localhost/saran");                 
                    this.addElement(uiComp);
                    uiComp.addChild(videoComp);
                    timer.addEventListener(TimerEvent.TIMER,timerHandler);
                    timer.start();
                private function netStatusHandler(event:NetStatusEvent):void
                    trace("Code ===>>>    "+event.info.code);
                    if(event.info.code == "NetConnection.Connect.Success")
                        connectStream(nc);
                private function connectStream(nc:NetConnection):void {
                    stream = new NetStream(nc);
                    videoComp.attachNetStream(stream);
                    stream.play("Terminator")
                    // stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                    stream.client = nsClient//new CustomClient();
                    nsClient.onMetaData = metadataHandler;
                    trace("stream ===>>>    "+stream.currentFPS);
                    //responder = new Responder(onResult);
                    // nc.call("getStreamLength", responder, "bikes" );
                private function metadataHandler(metadataObj:Object):void
                    meta = metadataObj;
                    videoComp.width = metadataObj.width;
                    videoComp.height = metadataObj.height;
                    //positionBar.move(videoComp.x, ((videoComp.y + videoComp.height)+20));
                    //positionBar.width = videoComp.width;
                    trace("Duration ====>>>>   "+meta.duration);
                private function timerHandler(event:TimerEvent):void
                    //trace("Timer called.........."+stream.time);
                    //positionBar.setProgress(stream.time, meta.duration);
            ]]>
        </fx:Script>
    </s:Application>

    I have the same question but I am using two pc's

  • How to use a key file in the FTP Task using and SSL connection

    In the past I have used this code to set the FTP pass word in an FTP component task in SSIS.
    Does anyone know how to use a Key file in an SSL connection to download a file from an FTP site?  If not can you tell me where I can get the C# code examples to learn how to create a script task or if there is another way in SSIS to download large files
    from an SSL FTP site?  Thank you for any help offered.
    public void Main()
    ConnectionManager FTPConn;
    FTPConn = Dts.Connections["FTPServer"];
    FTPConn.Properties["ServerPassword"].SetValue(FTPConn, Dts.Variables["FTPPassword"].Value);
    Dts.TaskResult = (int)ScriptResults.Success;
    Antonio

    You can use SFTP for this.
    This is a way of implementing SFTP in SSIS using standard tasks 
    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html
    also see
    http://blog.goanywheremft.com/2011/10/20/sftp-ftps-secure-ftp-transfers/
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to use my as3 file in flex

    hi, I am new in flex and want to divert into flex. How to  use my as3 file into flex. Is there any sample tutor . so, that I could learn fast.

    Please clarify. Is this .as file a class you previously used as a complonentcomponent you now wish to use as the main application?
    If the .as file just has variables and functions you wish to access from your Flex app, use:
    include "subfolder1/subfolder2/etc/MyASFile.as";
    If you want to use classes from the file, do this:
    import subfolder1.subfolder2.etc.MyClassName;
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services

  • How to use a CSS file  in a jspx page..

    I'm using JDev 10.1.3.4.
    I would like to know how can i use a CSS file in a JSPX page..
    there is this file: public_html\WEB-INF\temp\adf\styles\cache\oracle-desktop-10_1_3_4_0-en-ie-6-windows-s.css
    How do I make use of this is my jspx page?
    Also how do i use the style class in property inspector?
    What should be the path of "oracle-desktop-10_1_3_4_0-en-ie-6-windows-s.css"?
    Also please tell me what changes I have to make in all the other files like web.xml or adf-faces-config.xml.
    Im using web application template using (EJB,Toplink and JSF)
    Please suggest the detailed steps as I'm new to JSF.
    Thanks ,
    Shri

    under view put a new tag
    <f:view>
    <ui:script url="page.js"/>
    and thats it

  • Using Custom Config Files with WinForms

    I have created a new .config file for my application called "MyConfigFile.config" but I do not know how to reference, read or update it. Should I treat it as any other generic XML file?
    Rob E.

    The configuration file should be in the same directory as the application. The name of the configuration file should have the same name as the application with .config at the end. For example, an application called Watcher.exe should have
    a configuration file called Watcher.exe.config.
    To access the appSettings values from inside the program, use the AppSetting property of the ConfigurationSettings class.
    string title = System.Configuration.ConfigurationSettings.AppSettings["Title"];
    Two things should be kept in mind when accessing appSettings from the configuration file.One, the AppSetting could be null. Two, the AppSetting property always returns a string.When getting values from the configuration file, the code needs
    to handle these situations.
    One way to approach this is as follows:
    int AppSetValueMax = 0;
    if (ConfigurationSettings.AppSettings[key] != null)
    try
    AppSetValueMax = Convert.ToInt32(ConfigurationSettings.AppSettings["Max"]);
    catch(Exception e)
    //Exception Handling

  • Jaas How to specify the config file

    Hi
    I'm working on a web app based on Sun's App Server 8. I am implementing security using a Jaas LoginModule. I cant figure out how i can specify the config file because if i make the change in the java.security file the server throws all sorts of exceptions....... i'm not sure how i can go about that..
    Thanks..

    Read the documentation. There are several different files that you can use to specifiy the handler to use for a particular context. One is ${user.home}/.java.login.config

  • How to load a config file at appliaction startup

    Hi
    Is there a way to load a config file at application startup?
    I have the DB conection info in a config file.
    Right now m accessing that info by loading it using a classloader n then parsing it.
    When ever i access the DB this file is loaded n parsed.
    I want it to be loaded only once at startup n get cached.
    Then later on whenever i refer it, i shud get the cached copy.
    Is there a way to do this?

    Or you could just include a relevant static block.
    For instance you could have a utility class for accessing your DB in which you wrap jdbc code for querying, updating etc. This class would have code like the following:
    public class DBBean {
       private static DataSource ds = null;
       static {
          loadDataSource();
       public static loadDataSource() {
          // load your property file with the configuration info and setup your datasource
       public static void doSomething() {
          Connection con = ds.getConnection();
    }By placing initialization code in a public (?) method you can call this method to re-initialize your DataSource if e.g. you updated your datasource settings.
    Hope this helps

  • How to use an .xsl file to transform input XML to re-formatted output XML?

    Hello,
    I have a .xml file from a report that I want to use a stylesheet to transform into a different .xml format.
    I am reading that I can create a .xsl file to read my input and then transform it to a new output .xml file.
    How do I load this into the Apps?
    I tried creating a template definition and loading the .xsl in as type 'XSL-TEXT' and also, I added
    <?xml-stylesheet type="text/xsl" href="Transform.xsl"?> to my xml data source. The output looked the same as the input.
    Has anyone done this before? Any suggestions would be great!
    Thanks
    -CC

    This is how I use e4x with HTTPService:
    import mx.collections.XMLListCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable] private var claimsXLC:XMLListCollection;
    private function claimsHandler(evt:ResultEvent):void{
        claimsXLC = new XMLListCollection(evt.result..claim as XMLList);
    XML data is being returned, but I use XMLList to create the XMLListCollection.
    If this post answers your question or helps, please mark it as such.

  • How to use a excel file to create a service component?

    Dear all,
       I want to use a excel file to create a service to be my data source. I used the wizard to do that but i always got a message. "The data format is not valid, fields in each record must be delimited by tab charactors, and each record seperated by new line charactors". How should I reformat my excel file to fit the requirements? I have already chang the field`s format into 'text' type. Thx ^^

    Hi Louis,
    [Here|http://img125.imageshack.us/my.php?image=exceltestlo7.jpg] is the result of your data.  I downloaded your excel sheet and created a simulated service in 7.1.1 and it works fine.
    Below are the steps:
    1. Go to Tools -> service component wizard
    2. The popup opens : Step1 :  Enter the name of your service component
    3. Go to Excel spreadsheet Copy the data for which the service needs to be created.
    4. Step 2 : Paste the copied Excel data in the popup
    5. Step 3 : Define Input -> just click next
    6. Step 4: Define Conditions -> just click finish.
    Let me know if it helps.
    Good Luck,
    Dharmi

  • How to use a c file in LabVIEW

    Hi All,
    I have a c file which communicates through serial port and J1850 protocol. I want to use the C file in labview and do the communication through serial port.
    Can any one give me an idea how I have to use the c file in LabVIEW.
    Thank you.!
    ---------------- Be Good. Do Good. ---------------------

    Have you tried reading the LabVIEW Help or even searching this web site? This question has been asked MANY times. There's a section in the LabVIEW Help called "Calling Code Written in Text-Based Programming Languages." There are also several articles written on this. Here's just one: https://decibel.ni.com/content/docs/DOC-1690
    Please do the research and then come back with a more specific question.

  • How to use Parameter from file in window env

    hi All,
    Please tell me the how I can get Parameter from Saved file and can use in other file.
    EX:
    I want to use Password file for each instance like
    ORCL-manager
    ORCL_1-tiger
    ORCL_2-*****
    how to call this file in other file. using pasword for instance
    any help would be appereciated.
    Regards,

    You can use SFTP for this.
    This is a way of implementing SFTP in SSIS using standard tasks 
    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html
    also see
    http://blog.goanywheremft.com/2011/10/20/sftp-ftps-secure-ftp-transfers/
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to use a .dmg file in Arch Linux

    I have a file a friend gave me from his Mac computer with a .dmg file name. I haven't been able to pinpoint exactly how to use this type of file... I believe its an Apple raw disk image or something like that.. sort of like an iso. I need to use this file in order to start an application and download it onto Arch Linux. The problem is that I can't figure out how to use it on Arch Linux and burn it onto a Cd. Has anyone had experience with this sort of thing? I am completely lost.

    $ poweriso convert ~/Downloads/lang.rar/Rosetta_Stone_3.4.5.dmg -o ~/Downloads/lang.rar/rose.iso -o t
    PowerISO Copyright(C) 2004-2008 PowerISO Computing, Inc
    Type poweriso -? for help
    /home/user/Downloads/lang.rar/Rosetta_Stone_3.4.5.dmg: The file format is invalid or unsupported.
    $
    $ poweriso -?
    PowerISO Copyright(C) 2004-2008 PowerISO Computing, Inc
    Type poweriso -? for help
    Usage: poweriso <command> [parameters] [-switches]
    <Commands>
    list <image file> <directory> List files and directories in image file.
    Example: List all files and directories in root direcory of /home/sam/test.iso .
    Command: poweriso list /home/sam/test.iso / -r
    extract <image file> <dir/file name> Extract files/directories from image file.
    Example: Extract all files and directories in root direcory of /home/sam/test.iso
    to /home/sam/test recursively.
    Command: poweriso extract /home/sam/test.iso / -od /home/sam/test
    convert <image file> Convert image file to other format.
    Example: Convert /home/sam/test.daa to standard iso file
    Command: poweriso convert /home/sam/test.daa -o /home/sam/test.iso -ot iso
    <Switches>
    -r List or extract recursively.
    -o Specify output image file name.
    -od Specify output folder.
    -ot <iso|daa|bin> Specify output image file type. If not specified,
    the image type will be determined by file name suffix.
    -volsize <n> Split output image file to multiple volumes, and set volume
    size to <n>. Example: -volsize 100M
    -setpassword <password> Set password for output image file.
    Example: -setpassword 12345678
    $
    I tried to convert the file .dmg to an .iso so that I can easily burn that onto a disk and get the ball rolling.. am I missing something here?

  • How to use a .csv file as a database ?

    Hi everyone,
    I have a .csv file and I need to update some values in a column based on some condition. Basically I want to use the .csv file as a database such that I can perform query on it and update the result set as required.
    I am having trouble using csvjdbc though, can anyone give me a simple example about how to build a new database and import the csv file into it? Many thanks!!
    By the way, I tried a small program which was found online:
    import java.sql.*;
    public class test {
    public static void main(String args[]) throws Exception{
    Class.forName("org.relique.jdbc.csv.CsvDriver");
    System.out.println("I'm ok!");
    But I got an exception as following:
    Exception in thread "main" java.lang.ClassNotFoundException: org.relique.jdbc.csv.CsvDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at test.main(test.java:5)
    Could anyone tell me how to fix it? Thanks.
    Arjin

    It's because Class.forName will throw ClassNotFoundException if it cannot locate the class file. You need to set classpath so that org.relique.jdbc.csv.CsvDriver class can be located by ur code.

Maybe you are looking for