Example:
package com.w3schools;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
public class PropertyFileTest {
public static void main(String args[]){
OutputStream os = null;
Properties prop = new Properties();
prop.setProperty("name", "w3schools");
prop.setProperty("domain", "www.w3schools.com");
prop.setProperty("email", "[email protected]");
try {
os = new FileOutputStream("TestProp.properties");
prop.store(os, "Dynamic Property File");
System.out.println("Property file created successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
} |
package com.w3schools;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
public class PropertyFileTest {
public static void main(String args[]){
OutputStream os = null;
Properties prop = new Properties();
prop.setProperty("name", "w3schools");
prop.setProperty("domain", "www.w3schools.com");
prop.setProperty("email", "[email protected]");
try {
os = new FileOutputStream("TestProp.properties");
prop.store(os, "Dynamic Property File");
System.out.println("Property file created successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
TestProp.properties
#Dynamic Property File
#Sat Mar 17 16:13:03 IST 2018
email=hr@826.a00.myftpupload.com
name=w3schools
domain=www.w3schools.com |
#Dynamic Property File
#Sat Mar 17 16:13:03 IST 2018
[email protected]
name=w3schools
domain=www.w3schools.com
Download this example.