The properties files are generally used as configuration file for java programs.In Java, there is a special class for manipulating properties file called java.util.Properites. Properties are configuration values managed as key and value pairs since it is basically a Hashtable that can be saved/loaded from stream. In each pair, both key and value are String values.
Example Program for Reading Properties File
ReadProperties.java
import java.util.Properties;
import java.io.FileInputStream;
class ReadProperties {
public static void main(String arg[]) {
try {
Properties properties=new Properties();
properties.load(new FileInputStream("D:\\config.properties"));
System.out.println("Message from Properties file: "+ properties.getProperty("message"));
}
catch(Exception e) {
e.printStackTrace();
}
}
}
config.properties
message=All The Best
Output:
Message from Properties file: All The Best
Comments
Post a Comment