Generally in selenium, we used to use properties file for maintaining configuration related data of project like object locators and URL's.
In this post, I will show you how to read and write data from a properties file.
Please find below sample code for the same.
Sample code:
package DriverMethods;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertyFileReader {
Properties prop = new Properties();
FileInputStream file;
FileOutputStream fileOut;
//Reusable method for reading data
public String readingData(String key) throws IOException{
//path of properties file
file = new FileInputStream("path of property file");
// load a properties file
prop.load(file);
//get the value of key
String out=prop.getProperty(key);
return out;
}
//Reusable method for writing data
public void writeData(String key,String data) throws IOException{
//path of properties file
fileOut = new FileOutputStream("path of property file");
// set the value to key
prop.setProperty(key, data);
// save properties
prop.store(fileOut, null);
}
//Usage
public static void main(String[] args) throws IOException{
PropertyFileReader Pf = new PropertyFileReader();
System.out.println(Pf.readingData("username"));
Pf.writeData("password", "ShreyaGhosal");
}
}
In this post, I will show you how to read and write data from a properties file.
Please find below sample code for the same.
Sample code:
package DriverMethods;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertyFileReader {
Properties prop = new Properties();
FileInputStream file;
FileOutputStream fileOut;
//Reusable method for reading data
public String readingData(String key) throws IOException{
//path of properties file
file = new FileInputStream("path of property file");
// load a properties file
prop.load(file);
//get the value of key
String out=prop.getProperty(key);
return out;
}
//Reusable method for writing data
public void writeData(String key,String data) throws IOException{
//path of properties file
fileOut = new FileOutputStream("path of property file");
// set the value to key
prop.setProperty(key, data);
// save properties
prop.store(fileOut, null);
}
//Usage
public static void main(String[] args) throws IOException{
PropertyFileReader Pf = new PropertyFileReader();
System.out.println(Pf.readingData("username"));
Pf.writeData("password", "ShreyaGhosal");
}
}
amasya
ReplyDeletesinop
çorum
sakarya
van
CDH
goruntulu show
ReplyDeleteücretli
SMG8
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
46XVM
80C8C
ReplyDeleteDiyarbakır Evden Eve Nakliyat
Çerkezköy Parke Ustası
Ağrı Evden Eve Nakliyat
Giresun Evden Eve Nakliyat
Kayseri Evden Eve Nakliyat
BE5CF
ReplyDeleteAntalya Evden Eve Nakliyat
Silivri Fayans Ustası
Ankara Evden Eve Nakliyat
Binance Güvenilir mi
Gümüşhane Evden Eve Nakliyat
47E3B
ReplyDeleteYozgat Evden Eve Nakliyat
Ardahan Lojistik
Çerkezköy Oto Boya
Burdur Lojistik
Trabzon Şehirler Arası Nakliyat
Bilecik Şehirler Arası Nakliyat
Ünye Mutfak Dolabı
Keçiören Boya Ustası
Antalya Şehir İçi Nakliyat
6E7A3
ReplyDeleteshiba
pancakeswap
poocoin
sushi
aave
ellipal
trust wallet
ledger live
looksrare
BNHBGVFCDXS
ReplyDeleteشركة تسليك مجاري
شركة صيانة افران BiZvmkywJL
ReplyDeleteشركة مكافحة الحمام بالاحساء 2Ojf0FbxfK
ReplyDeleteتسليك مجاري بالاحساء lfeOGHMcka
ReplyDeleteشركة صيانة افران بالاحساء SQsHg9hwuk
ReplyDelete