Created
October 5, 2016 12:26
-
-
Save muthugit/aeef83226345ff21df73223a2cdcdac7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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