Thursday, December 27, 2012

Simple way to read properties file in Java

Copy pasted from Link: http://www.mkyong.com/java/java-properties-file-examples/

package com.mkyong.common;
 
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
 
public class App 
{
    public static void main( String[] args )
    {
     Properties prop = new Properties();
 
     try {
      //set the properties value
      prop.setProperty("database", "localhost");
      prop.setProperty("dbuser", "mkyong");
      prop.setProperty("dbpassword", "password");
 
      //save properties to project root folder
      prop.store(new FileOutputStream("config.properties"), null);
 
     } catch (IOException ex) {
      ex.printStackTrace();
        }
    }
}
 
package com.mkyong.common;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
 
public class App 
{
    public static void main( String[] args )
    {
     Properties prop = new Properties();
 
     try {
               //load a properties file
      prop.load(new FileInputStream("config.properties"));
 
               //get the property value and print it out
                System.out.println(prop.getProperty("database"));
      System.out.println(prop.getProperty("dbuser"));
      System.out.println(prop.getProperty("dbpassword"));
 
     } catch (IOException ex) {
      ex.printStackTrace();
        }
 
    }
}
 
package com.mkyong.common;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.utilutil.Properties;
 
public class App 
{
    public static void main( String[] args )
    {
     Properties prop = new Properties();
 
     try {
               //load a properties file from class path, inside static method
      prop.load(App.class.getClassLoader().getResourceAsStream("config.properties");));
 
               //get the property value and print it out
                System.out.println(prop.getProperty("database"));
      System.out.println(prop.getProperty("dbuser"));
      System.out.println(prop.getProperty("dbpassword"));
 
     } catch (IOException ex) {
      ex.printStackTrace();
        }
 
    }
}
 

94 comments:

  1. [url=http://www.onlinecasinos.gd]online casino[/url], also known as first-class casinos or Internet casinos, are online versions of illustrious ("chunk and mortar") casinos. Online casinos approve gamblers to deport oneself and wager on casino games philosophy pneuma the Internet.
    Online casinos typically enter upon aside on the superstore odds and payback percentages that are comparable to land-based casinos. Some online casinos exhort on higher payback percentages with a take off it slump dabble in shindy games, and some spill the beans the circulate about payout captivate audits on their websites. Assuming that the online casino is using an aptly programmed indefinitely infant up generator, proffer games like blackjack be blessed an established have the qualification in place of edge. The payout cut up after these games are established off non-standard boost to the rules of the game.
    Diverse online casinos agreement into portion publicly see or reason their software from companies like Microgaming, Realtime Gaming, Playtech, Worldwide Cunning Technology and CryptoLogic Inc.

    ReplyDelete
  2. xanax price the drug xanax use - xanax side effects in elderly

    ReplyDelete
  3. buy tramadol online order tramadol online forum - tramadol hcl xr

    ReplyDelete
  4. buy tramadol online buy cheap tramadol online - cheap tramadol usa

    ReplyDelete
  5. generic xanax xanax side effects dizziness - overdose from xanax

    ReplyDelete
  6. generic xanax xanax online illegal - xanax withdrawal can't sleep

    ReplyDelete
  7. buy tramadol online tramadol for dogs on empty stomach - tramadol no prescription needed

    ReplyDelete
  8. xanax online xanax 2mg online no prescription - generic xanax 3 mg

    ReplyDelete
  9. buy tramadol online buy tramadol online legit - is it legal to buy tramadol online usa

    ReplyDelete
  10. generic xanax xanax side effects alcohol - high on xanax bars

    ReplyDelete
  11. buy tramadol online tramadol dose for 40 lb dog - tramadol overnight cod delivery

    ReplyDelete
  12. buy tramadol online tramadol 100mg online overnight - cheap tramadol 180

    ReplyDelete
  13. buy tramadol online no prescription tramadol overdose dosage - tramadol side effects 50mg

    ReplyDelete
  14. xanax online xanax 7.5mg - buy xanax uk no prescription

    ReplyDelete
  15. buy tramadol online buy tramadol visa - tramadol dose vet

    ReplyDelete
  16. alprazolam xanax xanax and alcohol use - xanax generic pill identification

    ReplyDelete
  17. buy tramadol online tramadol 50 mg sleep - buy tramadol online safe

    ReplyDelete
  18. buy tramadol online can dog overdose tramadol - buy-cheap-tramadol.org

    ReplyDelete
  19. buy tramadol online buy tramadol cash delivery - buy tramadol online cod overnight

    ReplyDelete
  20. xanax online death by xanax overdose - xanax side effects webmd

    ReplyDelete
  21. xanax online eastbound down quotes xanax - xanax overdose wiki

    ReplyDelete
  22. xanax online xanax high liver enzymes - xanax withdrawal with klonopin

    ReplyDelete
  23. buy tramadol online tramadol withdrawal day 4 - buy tramadol online echeck

    ReplyDelete
  24. buy tramadol online buy tramadol usa pharmacy - buy tramadol cod free

    ReplyDelete
  25. generic xanax what is the generic of xanax - buy upjohn xanax online

    ReplyDelete
  26. buy tramadol online tramadol withdrawal many days - purchase tramadol

    ReplyDelete
  27. generic xanax 0.5 mg xanax effects - 2mg xanax high

    ReplyDelete
  28. soma carisoprodol is carisoprodol 350 mg a narcotic - carisoprodol online cod

    ReplyDelete
  29. alprazolam price xanax online ireland - purchase xanax online no prescription

    ReplyDelete
  30. carisoprodol 350 mg soma carisoprodol tablets 250mg - somacid 350 mg carisoprodol

    ReplyDelete
  31. generic tramadol buy tramadol online overnight shipping - order tramadol online mastercard

    ReplyDelete
  32. buy tramadol online tramadol kidney failure - long term tramadol addiction

    ReplyDelete
  33. carisoprodol 350 mg soma carisoprodol no prescription - carisoprodol 350 mg effects

    ReplyDelete
  34. buy tramadol online cheap tramadol pay us - cheap tramadol online cod

    ReplyDelete
  35. buy tramadol online ultram er vs tramadol - generic brand name tramadol

    ReplyDelete
  36. cialis online cialis free trial online - generic cialis soft tabs

    ReplyDelete
  37. order tramadol cheap tramadol line - buy tramadol online from usa

    ReplyDelete
  38. buy generic xanax xanax side effects stopping - 2mg xanax first time

    ReplyDelete
  39. buy cialis generic buy cialis soft tabs - cialis online rx

    ReplyDelete
  40. buy tramadol online tramadol no prescription overnight cod delivery - what does a generic tramadol look like

    ReplyDelete
  41. order cialis online cheap cialis overnight no prescription - cialis reviews for bph

    ReplyDelete
  42. buy generic cialis cialis rash - buy cialis super active online

    ReplyDelete
  43. xanax online generic xanax same xanax - there generic xanax

    ReplyDelete
  44. cialis online cialis online prescription order - cialis price at cvs

    ReplyDelete
  45. order xanax no prescription what xanax pills look like - xanax viagra drug interactions

    ReplyDelete
  46. generic xanax xanax bars drug test - alprazolam 0.5 mg tablet side effects

    ReplyDelete
  47. cheap tadalafil buy cialis online new zealand - buy cheap brand cialis

    ReplyDelete
  48. buy cialis online order cialis usa - buy cialis 5 mg online

    ReplyDelete
  49. xanax online side effects alprazolam 0.5 mg - how long xanax high last

    ReplyDelete
  50. cheapest cialis how to buy cialis in us - cialis 5mg online australia

    ReplyDelete
  51. cialis online cialis daily or 36 hour - price viagra versus cialis

    ReplyDelete
  52. http://landvoicelearning.com/#30896 generic tramadol online no prescription - buy tramadol for dogs

    ReplyDelete
  53. buy generic tramadol tramadol (ultram) 50 mg tablet - tramadol generic for ultram

    ReplyDelete
  54. http://landvoicelearning.com/#21906 tramadol toothache - tramadol hcl side effects 50mg

    ReplyDelete
  55. http://landvoicelearning.com/#21906 tramadol withdrawal oxycontin - tramadol hcl paracetamol

    ReplyDelete
  56. best buy tramadol tramadol hcl 50 mg vs oxycodone - buy discount tramadol

    ReplyDelete
  57. http://landvoicelearning.com/#38471 tramadol help vicodin withdrawal - tramadol 50 mg opiate

    ReplyDelete
  58. tramadol overnight shipping tramadol no prescription free shipping - tramadol dosage australia

    ReplyDelete
  59. legal buy tramadol online tramadol hcl 50mg dosage - tramadol withdrawal canine

    ReplyDelete
  60. buy tramadol tramadol 50mg usage - 8 50 mg tramadol

    ReplyDelete
  61. buy cheap tramadol tramadol order online tramadol 50g - tramadol compared to ultram

    ReplyDelete
  62. buy tramadol cheap tramadol 50mg capsules - buy tramadol online no prescription usa

    ReplyDelete
  63. We ωant the mаgic pill that inѕtantlу
    fixes ргοblems that haѵe takеn
    us yeaгs to crеate. Τhere are
    certain сhemicalѕ and hormonеs involved
    іn increasing the blood flοw to the pеnis.
    It only takеѕ а mοderate amount of exercіse and Ereсtile Dyѕfunction
    can be overcomе withοut the use of drugs.

    Τaκe a look at my web site cialis and alcohol medication
    Also see my webpage: mixing cialis and alcohol

    ReplyDelete
  64. buy tramadol tramadol no prescription us pharmacy - buy tramadol usa pharmacy

    ReplyDelete
  65. http://buytramadolonlinecool.com/#56411 order tramadol overnight cod - tramadol for dogs nausea

    ReplyDelete
  66. buy tramadol tramadol hydrochloride 50mg overdose - tramadol no prior prescription

    ReplyDelete
  67. http://landvoicelearning.com/#44827 tramadol for dogs euthanasia - 100mg tramadol is equivalent to what

    ReplyDelete
  68. buy tramadol online buy tramadol 100mg online - tramadol for dogs ok for people

    ReplyDelete
  69. buy tramadol tramadol 50 mg espanol - tramadol 50mg vs 100mg

    ReplyDelete
  70. buy tramadol tramadol 50 mg webmd - tramadol online pharmacy

    ReplyDelete
  71. http://landvoicelearning.com/#23561 legal buy tramadol online usa - buy tramadol online mastercard overnight

    ReplyDelete
  72. buy tramadol online can you buy tramadol online in usa - tramadol hcl abuse

    ReplyDelete
  73. learn how to buy tramdadol next day tramadol review - sniffing tramadol high

    ReplyDelete
  74. buy ativan online how quickly does ativan work - ativan uses for the elderly

    ReplyDelete
  75. buy tramadol tablets buy tramadol online usa - tramadol dosage paracetamol

    ReplyDelete
  76. http://reidmoody.com/#45570 ativan prolonged qt interval - ativan dosage levels

    ReplyDelete
  77. http://blog.dawn.com/dblog/buy/#40751 tramadol hcl 50 mg tablet - buy tramadol cod overnight delivery

    ReplyDelete
  78. tramadol 50 mg tramadol 200 mg get high - buy tramadol online overnight

    ReplyDelete
  79. ways to buy ativan online interaction of ativan and alcohol - ativan wiki

    ReplyDelete
  80. lorazepam drug buy lorazepam sublinguale - lorazepam 1 mg mylan

    ReplyDelete
  81. http://reidmoody.com/#45570 order ativan canada - ativan dosage amounts

    ReplyDelete
  82. http://ranchodelastortugas.com/#58720 xanax-effects.com - xanax joint and muscle pain

    ReplyDelete
  83. http://ranchodelastortugas.com/#93851 xanax side effects in women - xanax xr generic

    ReplyDelete
  84. http://staam.org/#90873 tramadol hcl 50 mg a narcotic - buyer tramadol online

    ReplyDelete
  85. oZzy moved away ever before, I miss his cock, and i am always hungry for intercourse.

    FUCK MY PUSSY!

    Here is my webpage hcg injections
    my site :: hcg injections

    ReplyDelete
  86. This web site really has all the info I neеded concеrning
    this subject аnd didn't know who to ask.

    Stop by my web blog; steroids and athletes
    my web page: buy injectable steroids

    ReplyDelete
  87. http://staam.org/#41652 buy tramadol online overnight delivery - tramadol 50 mg and naproxen

    ReplyDelete
  88. alprazolam cheap xanax prescription - klonopin generic xanax

    ReplyDelete
  89. I blog often and I genuinely appreciate your content.
    The article has truly peaked my interest. I am going
    to take a note of your website and keep checking for new
    details about once per week. I opted in for your RSS
    feed too.

    My web blog: cheap mac makeup

    ReplyDelete
  90. I believe this is among the so much important information for
    me. And i am satisfied reading your article. However wanna observation on
    few normal things, The site style is great, the articles is really nice
    : D. Excellent activity, cheers

    Here is my web-site; cheap ray ban wayfarer

    ReplyDelete
  91. Hmm is anyone else encountering problems with the images on this blog loading?
    I'm trying to figure out if its a problem on my end or if it's the blog.
    Any suggestions would be greatly appreciated.


    Feel free to surf to my web site - cheap mac cosmetics

    ReplyDelete
  92. Excellent article. Keep writing such kind of info
    on your page. Im really impressed by your site.
    Hello there, You've done a great job. I'll definitely digg it and individually suggest to my friends.
    I am sure they will be benefited from this site.

    My web page; wholesale oakley sunglasses

    ReplyDelete
  93. Τhis іs rеally іnterеsting, You
    are a verу skilled blοggeг.
    I have joined your гѕs fеed and look forwаrd to seeking
    more of yοur fantastic рοst. Also, I
    haѵе shared your site іn my social networks!


    my web blog: hcg weight loss scam

    ReplyDelete
  94. Hi there, Ι think your ωеbsite could be having browser
    compatibility problems. Whenevеr I take а
    look at youг blog in Safaгі,
    it looks finе however, when оpening in I.
    E., it's got some overlapping issues. I just wanted to give you a quick heads up! Other than that, great site!

    Here is my web site ... hcg drops diet

    ReplyDelete