集册 Java实例教程 写入属性

写入属性

欢马劈雪     最近更新时间:2020-01-02 10:19:05

424
写属性


import java.io.FileOutputStream;/** 时 代 J a v a - N o w J a v a . c o m 提供 **/

import java.io.IOException;

import java.io.OutputStream;

import java.util.Properties;


public class WriteProperties {


    public final static void main(String[] args) {

        Properties prop = new Properties();

        OutputStream output = null;


        try {


            output = new FileOutputStream("config.properties");
/** 来自 N o w  J a v a  .   c o m**/

            // set the properties value

            prop.setProperty("database", "localhost");

            prop.setProperty("dbuser", "user name");

            prop.setProperty("dbpassword", "password");


            // save properties to project root folder

            prop.store(output, null);


        } catch (IOException io) {

            io.printStackTrace();

        } finally {

            
展开阅读全文