Properties配置文件的读取

Properties概述:以properties为后缀的文件,存储形式为一个键值对,可以通过键获取值
Properties作为Map集合的使用
Properties的特殊功能
public Object setProperty(String key,String value)
public String getProperty(String key)
public Set stringPropertyNames()
Properties和IO流的结合使用
public void load(Reader reader)
public void store(Writer writer,String comments)

配置文件的读取

            //去数据库中查询用户数据,若查到结果集是有数据的
//        String url = "jdbc:mysql://192.168.136.100:3306/bigdata31?useUnicode=true&characterEncoding=utf-8&useSSL=false";
//        String username2 = "root";
//        String password2 = "123456";
            //读取配置文件,获取键对应的值
            //创建Properties类对象
            Properties properties = new Properties();
            //指定要读取的配置文件
            properties.load(new BufferedReader(new FileReader("src/com/shujia/day18/confs/info.properties")));
            //getProperty()  通过键获取对应的值
            String url = properties.getProperty("url");
            String username2 = properties.getProperty("user");
            String password2 = properties.getProperty("password");
            Connection conn = MysqlTool.getConnection(url, username2, password2);
            System.out.println("成功获取与数据库的链接对象:"+conn);

Properties配置文件

posted @ 2024-08-18 17:01  ていせい  阅读(27)  评论(0)    收藏  举报