服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java核心代码例程之:propertiesdemo.java


import java.util.*;
import java.io.*;


/**
 * demonstrates how to sort strings.
 ***/
public class propertiesdemo
{
    public static void main(string args[]) throws exception
    {
        properties props = new properties();
        props.put("db.user", "jack");
        props.put("db.password", "opendoor");
        
        // getproperty will return the value if found, otherwise null
        system.out.println(props.getproperty("db.user"));
        
        // getproperty will return the value if found, otherwise "none"
        system.out.println(props.getproperty("db.password", "none"));
        
        /*
        // you can also load properties from a file
        fileinputstream fis = new fileinputstream("my.properties");
        props.load(fis);
        fis.close();
        **/
    }
}

扫描关注微信公众号