This example shows how to create a property file and set the property values to it.
Here is my java class
Explanation:
Here is my java class
package com.externalProperties; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; /** * * @author Janardhan Randhi */ public class SetPropertiesFile { public static void main(String[] args) throws FileNotFoundException, IOException { Properties p = new Properties(); p.setProperty("FirstName", "Janardhan"); p.setProperty("LastName", "Randhi"); p.setProperty("Website", "JavaSnippets"); p.setProperty("Address", "Vizianagaram"); OutputStream out = new FileOutputStream(new File("Snippets.properties")); p.store(out, "FileStored"); } }
- Create a property class instance.
- Using the setProperty method to set the properties to the properties file.
- Create the FileOutputStream to write the data into the output file. it is key and value pair.
- Using the store method to store the data in the output file.