How to read data from properties file:
=============================
abc.properties:
--------------------
element_Username = rameshat914@gmail.com
element_Next = selenium
element_Password = real time
element_Signin = expert
PropertiesDemo.java:
---------------------------
package files;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("D:\\ramesh\\sampleproject\\src\\files\\OR.properties");
Properties properties = new Properties();
properties.load(fileInputStream);
String gmailUserName = properties.getProperty("element_Username");
String gmailNext = properties.getProperty("element_Username");
String gmailPassword = properties.getProperty("element_Username");
String gmailSignin = properties.getProperty("element_Username");
System.out.println(gmailUserName);
System.out.println(gmailNext);
System.out.println(gmailPassword);
System.out.println(gmailSignin);
}
}
=============================
abc.properties:
--------------------
element_Username = rameshat914@gmail.com
element_Next = selenium
element_Password = real time
element_Signin = expert
PropertiesDemo.java:
---------------------------
package files;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("D:\\ramesh\\sampleproject\\src\\files\\OR.properties");
Properties properties = new Properties();
properties.load(fileInputStream);
String gmailUserName = properties.getProperty("element_Username");
String gmailNext = properties.getProperty("element_Username");
String gmailPassword = properties.getProperty("element_Username");
String gmailSignin = properties.getProperty("element_Username");
System.out.println(gmailUserName);
System.out.println(gmailNext);
System.out.println(gmailPassword);
System.out.println(gmailSignin);
}
}
No comments:
Post a Comment