public static String readPropFile() throws IOException
{
Properties prop = new Properties();
String job = "";
try {
//BaseFunction is class name where function is defined
InputStream inputStream = BaseFunction.class.getClassLoader().getResourceAsStream("config.properties");
prop.load(inputStream);
job = prop.getProperty("Job");
System.out.println(job);
} catch (IOException e) {
e.printStackTrace();
}
return job;
}
{
Properties prop = new Properties();
String job = "";
try {
//BaseFunction is class name where function is defined
InputStream inputStream = BaseFunction.class.getClassLoader().getResourceAsStream("config.properties");
prop.load(inputStream);
job = prop.getProperty("Job");
System.out.println(job);
} catch (IOException e) {
e.printStackTrace();
}
return job;
}
Reading a property file is simple thing, for reading a property file we have create a property object
InputStream inputStream = BaseFunction.class.getClassLoader().getResourceAsStream("config.properties");
InputStream inputStream = BaseFunction.class.getClassLoader().getResourceAsStream("config.properties");
Where config.properties is the name of the property file. For getting the value from file
prop.load(inputStream);
job = prop.getProperty("Job");
using the above code we can read the data to a string variable. I have defined value of the job as Job=Oracle, if print the value in the variable job the result will be Oracle.
prop.load(inputStream);
job = prop.getProperty("Job");
using the above code we can read the data to a string variable. I have defined value of the job as Job=Oracle, if print the value in the variable job the result will be Oracle.
No comments:
Post a Comment