Retreiving only particular keys from a properties file

hello friends,
can someone kindly tell me , is there any way to retreive only particular keys from a properties file .
for e.g the file is as follows
abc.properties
ad_1 = "hello"
ad_1_fg = "bye"
ad_1_hj = "dfd"
ad_1_jk = "sdfsdf"
bk_2_jk = "sdfdsf"
bk_2_lk = "klklk"
so lets say at run time , i get the key ad_1 , and i am told to retreive all the keys from the properties file starting only with ad_1, then how do i do it.
I tried using ResourceBundl,PropertyResourceBundle, but they all get all the keys, and tehre is no way to specify within them that get only keys with particular format.
please do help me

Retrieve all the properties, and then loop over them
looking for those whose names match the pattern you
need.hello jverd thanks for your quick response, i was thinking the same, but lets say i retreive all keys, then how do i match them to my pattern, i mean if some keys is like this jhk_ad_1 , so i dont want that , i only want keys starting from ad_1 , hope u got what i am trying to say.
i mean i want all the keys that are starting from the runtime value i am getting

Similar Messages

  • Reading all related keys from a properties file

    I have in my propeties file, keys the following way:
    FIRST_DATASOURCE=COM.XYZ.ABCSERVER.JDBC1
    SECOND_DATASOURCE=COM.ABC.SERVER2.JDBC1
    FIRST_DATASOURCE=COM.123.SERVER3.JDBC3What is the solution to read all the keys wit _DATASOURCE and return as a string array?
    Thanks in advance.

    Thanks kajbj..
    The problem here is the datasources are added from
    time to time and the program should pick-up
    dynamically.
    If I hardcode for the existing available datasources,
    how can it handle for the future?
    Appreciate your thoughts.Many answer can be found by reading API
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#propertyNames()

  • Execute java code taken from a properties file

    I have a requirement to store some java code in the Properties file & use the code inside the program later. Is there a way I can execute this code after I get it from the .properties file which is retrieved using the ResourceBundle?
    Example:
    File: system.properties
    Item_list=blocksBean.menu(QueryValue,request.getContextPath())
    Inside my Java program I'm using this..
    theBody=codesBean.replaceAll(theBody, "%%menu%%",ResourceBundle.getBundle("system").getString("Item_list"), true);
    instead of
    theBody=codesBean.replaceAll(theBody, "%%menu%%",blocksBean.menu(QueryValue,request.getContextPath()), true);
    This doesn't work because ResourceBundle.getBundle("... returns the value.. which is a string "blocksBean.menu(QueryValue,request.getContextPath())". But what I need is it has to be executed..
    blocksBean.menu() returns a string value of html code fetched from the dartabase.
    Is there a way I can execute blocksBean.menu() which is retrieved from the .properties file.. If anyone has done it / have an idea on this.. please e-mail me [email protected]
    I need something like an eval() in javaScript..
    Thanks in advance
    -ashok

    These boys might have something that will help you:
    http://www.beanshell.org/
    Good luck
    Lee

  • Hi i am trying to write a program which reads from a properties file the pr

    hi,
    this is ayesha.
    I am trying to write a program wherein i will be reading the value of a property from a properties file which will be true initially. I want to loop in there till the time when the value of the property is false.
    The code is as follows:
    public static void main(String[] args) {
              ReadingAPropertiesFile propers=new ReadingAPropertiesFile();
              propers.ReadingFileRegularly("F:\\ayesha.properties");
    public String ReadingFileRegularly(String FilePath){
              Properties props = new Properties();
              String message;
              String filePath=FilePath;
              try {
    props.load(new FileInputStream(filePath));
    message = props.getProperty("ayesha");
         boolean theValue = Boolean.parseBoolean(message);
         while(theValue){
              System.out.println("trueeeeeeeeeeeeeeeeeeeeeee");
              Thread.sleep(60000);
              ReadingFileRegularly(filePath);
              catch(Exception ex){
                   ex.printStackTrace();
              String messagean="something";
              return messagean;
    The contents of ayesha.properties are :
    ayesha=true
    After 5 minutes it will be set to false so i want to loop in there till the value of ayesha=false at which time i will return
    But i dont know how to loop in there for that time:
    while(theValue) ?????????????/ what after this???????????
    Any suggestons are awaited.

    ayeshaparween wrote:
    hi,
    this is ayesha.
    I am trying to write a program wherein i will be reading the value of a property from a properties file which will be true initially. I want to loop in there till the time when the value of the property is false.
    The code is as follows:
    public static void main(String[] args) {
              ReadingAPropertiesFile propers=new ReadingAPropertiesFile();
              propers.ReadingFileRegularly("F:\\ayesha.properties");
    public String ReadingFileRegularly(String FilePath){
              Properties props = new Properties();
              String message;
              String filePath=FilePath;
              try {
    props.load(new FileInputStream(filePath));
    message = props.getProperty("ayesha");
         boolean theValue = Boolean.parseBoolean(message);
         while(theValue){
              System.out.println("trueeeeeeeeeeeeeeeeeeeeeee");
              Thread.sleep(60000);
              ReadingFileRegularly(filePath);//recursive call this is a bad idea might result in stack overflow error
              catch(Exception ex){
                   ex.printStackTrace();
              String messagean="something";
              return messagean;
    The contents of ayesha.properties are :
    ayesha=true
    After 5 minutes it will be set to false so i want to loop in there till the value of ayesha=false at which time i will return
    But i dont know how to loop in there for that time:
    while(theValue) ?????????????/ what after this???????????
    Any suggestons are awaited.I think you better rethink your design , do not use recursion, I would normally use a loop like you did but without loading the content of the file each time, I would use File.l lastModified() method and compare with previous results from this method to see if the file was modified. Then if it was modified then load the new File and check if the property value has changed.

  • How to read from a .properties file...?

    Hello all,
    I'm new to this forum.
    I have a problem in reading data from .properties file...
    Follow is my properties file...
    log4j.properties
    log4j.rootLogger=warn, file, mail
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.maxFileSize=100KB
    log4j.appender.file.maxBackupIndex=5
    log4j.appender.file.File=D:\log.txt
    log4j.appender.file.threshold=info
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    #email appender
    log4j.appender.mail=org.apache.log4j.net.SMTPAppender
    #defines how othen emails are send
    log4j.appender.mail.BufferSize=1
    log4j.appender.mail.SMTPHost="smtp.Honeywell.com"
    log4j.appender.mail.From=[email protected]
    log4j.appender.mail.To=[email protected]
    log4j.appender.mail.Subject=Log ...
    log4j.appender.mail.threshold=error
    log4j.appender.mail.layout=org.apache.log4j.PatternLayout
    log4j.appender.mail.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    I want to access file path given in .properties file..
    I'm coding like this...
    Properties props = new Properties();
    String p=props.getProperty("file.FILE");
    The above code is not getting me the string.. it shows null value...
    Any solution...?
    Thanks in advance......

    RahulSharna wrote:
    public Properties getProperties(String fileName)throws Exception{
    Properties prop = null;
    FileInputStream fis = null;
    Exception e = null;
    File file = new File(fileName);
    if(!file.exists())
    new FileNotFoundException(fileName);
    try{
    prop = new Properties();
    fis = new FileInputStream(file);
    prop.load(fis);
    }catch(Exception exp){
    e = exp;
    }finally{
    if(fis != null){try{fis.close();}catch(Exception ep){}}
    fis = null;
    file = null;
    if(e != null)
    throw e;
    return prop;
    }Hope the above snippet helps :)
    REGARDS,
    RaHuLYou do know that you can throw out of the catch block without "short-circuiting" the finally block, right? Making the declaration of e completely foolish. (Unless you actually want to do something after the try/catch block, of course.) And, if all you're going to do is throw the exception anyway, why bother catching it?

  • How can I read "Keys" from a Config File that have square brackets in them?

    I'm using the "Read Key (String).vi" from the config.llb and I'm having a problem because the key names in my file have square brackets in them. I'm creating an VI to read certain pieces of the TestStand �StationGlobals.ini� file and array elements appear as %[0] = "blah blah blah". It looks like they're not getting recognized at all. Is there a way to handle this?

    I was just looking at the code inside the configuration VIs and the way they work under V6 is that the Open VI actually reads the contents of the configuration file, parses it (in nice-platform independent G) and stores it in a fancy LV2-style global called the "Config Data Registry.vi". The routine that does the parsing is called "String to Config Data.vi". My gut reaction is that this code is going to be the same in your version because between sometime prior to V6 of LV, NI changed the location of a couple terminals on the low-level Match String function and it looks like when this code was originally written the terminals were in the old configuration.
    In any case, if your square-bracket containing strings are getting lost, this is probib
    ly where it's happening at. The other place to check is in the read VI itself. The V6 VI for reading the configuration registry is called "Config Data Get Key Value.vi". It's output is then further parsed by a function called "Parse Store String.vi" if the "read raw string?" input is set to False (the default position).
    Given that all the code for these functions are written in LV, you should be able to fix your VIs to read the strings you have in the ini file now. Which IMHO is actually the way they should work.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to create an Object array(two dimensional) from a properties file..

    Hi All..
    I have a typical problem..
    I have a properties file with key/value pairs . Now what I want to do is.. I need to read all the keys and the values corresponding to that keys and then create a two dimensional array.. Like..
    Properties props;
    Object[][] contents;
    My contents should be like
    contents = {{key1,value1},{key2,value2},{key3,value3},...};
    Can someone tell me how to do this.. asap...
    TIA
    CK

    Just because something is difficult for you does not qualify it as an "Advance Language Topic"... And it certainly doesn't allow you to multi-post.

  • How to obtain public key from a .crt file

    Hi
    I am new to cryptography Please correct me if my understanding regarding the digital signature is correct and i need help to get the public key.
    I have a x.crt file which contains following fields
    1) x
    2)y
    3) Certificate
    this certificate contains following fields
    certificate version
    owner id
    name
    public key
    signature (which is obtained by signing from start of x.crt till public key with private key)
    now i need to verify whether the signature for that i need to get the public key & signature from this .crt file. Is it how i need to verify the certificate ?? please help me as I am a newbie in cryptography

    Hi all
    Thanks for the reply
    So to get the public key now i used the following code
    byte[] dataPub = new byte[256]; // size of the public key
    try {
                        byteArrayInputStream.read(dataPub);
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
              BigInteger modulus = new BigInteger(dataPub);
         BigInteger exponent = new BigInteger("65537"); // specified in the document
         RSAPublicKeySpec rpks = new RSAPublicKeySpec(modulus, exponent);
         KeyFactory kf = null;
                   try {
                        kf = KeyFactory.getInstance("RSA");
                   } catch (NoSuchAlgorithmException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
         try {
                        pk = kf.generatePublic(rpks);
                        System.out.println("Pb Key----------------:"+pk.toString());
                   } catch (InvalidKeySpecException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
    When I convert the pk.toString I am getting a negative modulus value . Can the modulus value be negative ??
    Edited by: 800317 on Oct 8, 2010 5:51 AM

  • How to store ,retreive and edit  data from an xml file

    I am new to XML. I am creating a phone book in JSP with backend as an XML file.How can I store retrieve and edit datas from a jsp file.
    Please provide me with examples.I dont want to use bean.
    Please provide examples

    You will have to do some leg-work yourself. You will probably want to use DOM to parse and manipulate your XML data. Xerces (xml.apache.org) is a good open source parser. There are extensive examples on their site.
    - Saish

  • Unable to open only particular website from office which is site to site VPN site with juniper firewall

    All,
    when I tried to open a website I am getting request timed out after few minutes ,I have done a wireshark capture but unable to identify the problem particularly the url /timetracking/home.asp is not working ,can you help out here. please find attached capture from source to destination and vice versa.
    Thanks in advance.

    Yes, I tried that.  It did not work for me.
    I have 4 site collections.  The main site collection is the only one that I receive the error.  
    When the user clicks on the email link  and opens the document for approval, they receive the following error when they click on "Open This Task". 
    Element '{http://www.w3.org/1999/xhtml}a is unexpected according to content model of
    parent element '{http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields}Body'.
    There is nothing wrong with the task list itself, just the link from the Office 2010 client. 
    I am wondering if there is a web config or other file on the server that is specific to the site collection??
    Tracey

  • I had upgraded to firefox 3.0 years ago and lost my firefox 2.0 bookmarks. How do I retrieve them? I keep getting only one bookmark from the html file.

    Years back I had installed Firefox 3.0 (at launch, so not beta) into a separate program folder. After installation, I expected to have my bookmarks saved. Recently I found out my bookmarks were in application data and I found out I had one profile. That meant that my firefox 2.0 bookmarks were replaced.
    I read up on the FAQs and it stated that bookmark backups only save the previous 5 days or so, so I don't think they are usable though I have them saved. The bookmarks.html file in my profile shows only one bookmark after importing it into firefox 3.5 and firefox 2.0 (downgraded back to check it out), google chrome, and internet explorer. I still have the bookmarks.bak and bookmarks.html.bak files as well.
    A little backstory before I got up to this point because it's a bit convoluted because I thought I could retrieve them like IE favorites which were easy:
    1) Switched to Firefox 2.0 from Internet Explorer and got several hundred bookmarks.
    2) Got HyperBookmarks add-on which bugged up and replaced my previous bookmarks folder though it stated in FAQs that my original Firefox 2.0 bookmarks were in a separate folder so I didn't worry about it.
    3) Upgraded to Firefox 3.0 and it replaced all my bookmarks with nothing in bookmarks list. I thought it was saved because I installed Firefox 3.0 in a separate folder.
    4) Retrieved 3.0 Bookmarks and Archived them, but wasn't able to find Firefox 2.0 Bookmarks (original) nor the HyperBK version, except in HyperBk Backups folder.

    In the "Edit this Bookmark" window, use the 2nd drop-down button, that is to the right of the "Folder", to open a larger window that will allow more folder to appear. See the sloppy red arrow on the screenshot below.

  • I would like to get only specific channels from several .csv files and concatenate into one group.

    Hello,
    I am working with other groups and getting the data in daily .csv files.  When I use the "concatenate groups" script along with a script on importing files, I end up getting a huge file that takes about an hour to concatenate.  In order to reduce the amount of time and memory that this takes, I was hoping that someone could help me modify the script so that I could just list the channel name that I am interested in and concatinating only those channels rather than all of them. 
    For example, if voltage, temperature, pressure and time data are taken daily for 30 days, I would like to import only the temperature and time data (from .csv format) and concatenate into one group.
    I have attached the .vbs files that I use.
    Thanks in advance,
    Alan
    Attachments:
    Import and concatenate files.zip ‏9 KB

    Hi Alan,
    Actually, the feature you're asking for is already in the code of mine that you sent back. Look on line 11 of the main VBScript:    ChannelSet = "" ' "" or "1-" (DataPlugin) or "Sheet1" (EXCEL Wizard) 
    If this "ChannelSet" parameter is set to something other than "" or "1-" then it is used in line 78:
    Call DataFileLoadSel(FilePaths(i), DataPlugin, ChannelSet) 
    Yo can specify the channel indices to load with an expression like this:
    ChannelSet = "[1]/[1],[3]" 
    Let me know if you have further questions,
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Uploading data from a particular column of a particular sheet from an excel file into internal table

    Hi,
    I have to upload data in the first coulmn of 7th sheet of an excel file.
    Can anyone please help me on this.
    This link works perfectly fine for excel files without Macros.
    Read multiple sheets of an Excel file into SAP through ABAP - Code Gallery - SCN Wiki
    But my excel file has some macros.
    And after the macro enable/disable popup is cleared, the system freezes.
    Can someone pease help me on this abd tell me an approach different from the one in the above link?

    Welcome to SCN
    Please search before you post next time:BDC, upload data from multi excel sheets

  • How can i remove a key and its value from properties file

    hi all,
    i want remove a particular key and associated value from the
    properties file. is their any standard way of doing?
    thanks inadvance
    daya

    hi,
    thanks
    i am able to remove the key,
    one more question how can avoid storing date and time
    in properties file.
    thanks
    daya

  • Exception while loading properties from an xml file

    Hi all,
    I've got a problem while loading properties from an XML file:
    java.lang.ClassCastException: org.apache.xerces.dom.DeferredCommentImpl cannot be cast to org.w3c.dom.Element
    ERROR - Cannot load properties from the specified file <./conf/login.prop> java.lang.ClassCastException: org.apache.xerces.dom.DeferredCommentImpl cannot be cast to org.w3c.dom.Element
         at java.util.XMLUtils.importProperties(XMLUtils.java:97)
         at java.util.XMLUtils.load(XMLUtils.java:69)
         at java.util.Properties.loadFromXML(Properties.java:852)
         at g2.utility.HRPMProperties.<init>(HRPMProperties.java:78)
         at g2.utility.HRPMProperties.getInstance(HRPMProperties.java:94)
         at g2.gui.workers.ApplicationSwingWorker.<init>(ApplicationSwingWorker.java:36)
         at g2.main.Main.main(Main.java:37)but this code worked before, and I've got the xerces and xercesImpl packages in the classpath, anyone can give me an hint on how to fix the problem?

    Here there's the code that instantiates the HRPMProperties object loading the property file:
    public class HRPMProperties extends Properties {
         * A reference to myself.
        protected static HRPMProperties mySelf = null;
         * The property file to which load the configuration.
        protected static String propertyFile = "./conf/login.prop";
          * A set of static strings used as keys in the properties file.
         public final static String DATABASE_URL = "database_url";
         public final static String DATABASE_USERNAME = "database_username";
         public final static String DATABASE_PASSWORD = "database_password";
         public final static String REAL_USERNAME = "real_username";
         public final static String REAL_PASSWORD = "real_password";
         public final static String PHANTOM_LOGIN = "login_thru_phantom_user";
         public final static String AUTOCONNECT = "autoconnect";
         public final static String TRANSLATION_FILE = "translation_file";
         * Builds up an empty properties map.
        protected HRPMProperties(){
         super();
         this.reload();
         * Builds up the property map from the specified input file. <B> The file must be in XML format</B>.
         * In case of exception and/or problems reading from the specified file, an empty property map is returned.
         * @param fileName the path and the name of the file with the XML representation of the properties.
        protected HRPMProperties(String fileName){
         super();
         try{
             this.loadFromXML(new FileInputStream(fileName));        
         }catch(Exception e){
             Logger.error("Cannot load properties from the specified file <"+fileName+"> " + e);
             e.printStackTrace();
         * Provides an instance of the property class loaded from the default configuration file.
         * @return the property instance
        public static final HRPMProperties getInstance(){
         if( HRPMProperties.mySelf != null )
             return HRPMProperties.mySelf;
         else{
             HRPMProperties.mySelf = new HRPMProperties(HRPMProperties.propertyFile);
             return HRPMProperties.mySelf;
    }The constructor is the one triggering the exception, so there's a problem loading the XML property file.

Maybe you are looking for