Read and Write Properties File
In this post, I will tell you that how will you implement the utility to read and write the properties file. When you need to design an automation framework there are some utilities which you need to implement for reading and writing different types of files in your framework used for different purposes. The properties file is one of the best ways used to define the system configuration.
Code:-
public class PropFileHandler {
static Properties properties = new Properties();
public String readProperty(String property) {
InputStream inPropFile = null;
try {
inPropFile = new FileInputStream("Directory Path");
properties.load(inPropFile);
} catch (IOException e) {
System.out.println("There was Exception reading the Test data");
}
String value = properties.getProperty(property);
return value;
}
public static void writeProperty(String property, String value) {
try {
InputStream inPropFile = new FileInputStream("File Path");
properties.load(inPropFile);
inPropFile.close();
OutputStream outPropFile = new FileOutputStream("File Path");
properties.setProperty(property, value);
properties.store(outPropFile, null);
outPropFile.close();
} catch (IOException e) {
}
}
}
Thank you for reading my Post. Please like and comment if you like my post.
Code:-
public class PropFileHandler {
static Properties properties = new Properties();
public String readProperty(String property) {
InputStream inPropFile = null;
try {
inPropFile = new FileInputStream("Directory Path");
properties.load(inPropFile);
} catch (IOException e) {
System.out.println("There was Exception reading the Test data");
}
String value = properties.getProperty(property);
return value;
}
public static void writeProperty(String property, String value) {
try {
InputStream inPropFile = new FileInputStream("File Path");
properties.load(inPropFile);
inPropFile.close();
OutputStream outPropFile = new FileOutputStream("File Path");
properties.setProperty(property, value);
properties.store(outPropFile, null);
outPropFile.close();
} catch (IOException e) {
}
}
}
Thank you for reading my Post. Please like and comment if you like my post.
Labels: how to read and write properties file in java, java program to read and write properties file, read and write a properties file java, Read and Write Properties File, Read and Write Properties File in java
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home