Skip to content

Instantly share code, notes, and snippets.

@kbilel
Last active April 25, 2018 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbilel/90b0d167b6fd17c2f830b9b12c60e947 to your computer and use it in GitHub Desktop.
Save kbilel/90b0d167b6fd17c2f830b9b12c60e947 to your computer and use it in GitHub Desktop.
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