Last active
April 25, 2018 14:53
-
-
Save kbilel/90b0d167b6fd17c2f830b9b12c60e947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ContactUtils; | |
import java.io.InputStream; | |
import java.util.Properties; | |
public class PropertiesLookup { | |
Properties prop = new Properties(); | |
String filename = "config.properties"; | |
InputStream input = null; | |
public PropertiesLookup() { | |
try { | |
input = getClass().getClassLoader().getResourceAsStream(filename); | |
if (input == null) { | |
System.out.println("Sorry, unable to find " + filename); | |
return; | |
} | |
prop.load(input); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public String getProperty(String key) { | |
return prop.getProperty(key); | |
} | |
} | |
package com.client; | |
import ContactUtils.PropertiesLookup; | |
public class GarbageRun { | |
public static void main(String[] args) { | |
PropertiesLookup pl = new PropertiesLookup(); | |
String pValue = pl.getProperty("property1"); | |
System.out.println(pValue); | |
} | |
} | |
config.properties | |
property1=myname | |
property2 =mylastname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment