Example:
package com.w3spoint;
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", "w3spoint");
prop.setProperty("domain", "www.w3spoint.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.w3spoint; 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", "w3spoint");
prop.setProperty("domain", "www.w3spoint.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=w3spoint
domain=www.w3spoint.com |
#Dynamic Property File
#Sat Mar 17 16:13:03 IST 2018
email=[email protected]
name=w3spoint
domain=www.w3spoint.com
Download this example.