What is load() and store() method of Properties?

Using these two methods we can store and load the elements of Properties to a disk.

Writing property to a file:
import java.util.*;
import java.io.*;
class demo1
{
public static void main(String[] args)throws IOException{
Properties prop=new Properties();
prop.setProperty("x","bhabani");
prop.setProperty("a","samar");
prop.setProperty("b","gaura");
prop.setProperty("j","milan");
prop.store(new FileOutputStream("property.txt"),"namefile");
System.out.println(prop);
}};
Reading property from a file:
import java.util.*;
import java.io.*;
class demo1
{
public static void main(String[] args)throws IOException{
Properties prop=new Properties();
prop.load(new FileInputStream("property.txt"));
System.out.println(prop);
}};

No comments:

Post a Comment