Skip to content

Instantly share code, notes, and snippets.

@muthugit
Created October 5, 2016 12:26
Show Gist options
  • Save muthugit/aeef83226345ff21df73223a2cdcdac7 to your computer and use it in GitHub Desktop.
Save muthugit/aeef83226345ff21df73223a2cdcdac7 to your computer and use it in GitHub Desktop.
package test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ReadProperties {
public static void main(String[] args) {
ReadProperties obj = new ReadProperties();
try {
obj.getProperties();
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("unused")
public String getProperties() throws IOException {
String result = "";
InputStream inputStream = null;
try {
Properties prop = new Properties();
String propFileName = System.getProperty("user.dir") + "/src/test/config.properties";
inputStream = new FileInputStream(propFileName);
if (inputStream != null) {
prop.load(inputStream);
} else {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}
System.out.println(prop.get("myName"));
System.out.println(prop.getProperty("myName"));
} catch (Exception e) {
System.out.println("Exception: " + e);
} finally {
inputStream.close();
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment