首页 > 学院 > 开发设计 > 正文

Java核心代码例程之:PropertiesDemo.java

2019-11-18 15:17:06
字体:
来源:转载
供稿:网友

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();
        **/
    }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表