Sunday, April 26, 2020
Read value from properties file
To get the value of database connection or fetch labels for JSP, it is better to use properties file. So that if you change at one place, it will be reflected to all places.
Code to read properties file and return value
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ReadLabelProperties {
public static String getProperties(String key) throws IOException
{
InputStream inputStream=ReadLabelProperties.class.getClassLoader().getResourceAsStream("label.properties");
Properties myproperties = new Properties();
myproperties.load(inputStream);
return myproperties.getProperty(key);
}
}
label.properties are having entries like below
dbserver=jdbc:mysql://localhost:3306/
dbdriver=com.mysql.jdbc.Driver
Hope the same is useful while creating web application
Deepak
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment