Monday 8 February 2016

How to write data in to a properties file

How to write data in to a properties file:
===============================
package files;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesWriteDemo {

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);

properties.setProperty("name", "ramesh");

properties.setProperty("course", "selenium experts");

FileOutputStream fileOutputStream = new FileOutputStream("D:\\ramesh\\sampleproject\\src\\files\\OR.properties");

properties.store(fileOutputStream, "data is added into or.properties file");


System.out.println(properties.getProperty("name"));

System.out.println(properties.getProperty("course"));

}

}

No comments:

Post a Comment