美文网首页
使用Properties类读取配置文件

使用Properties类读取配置文件

作者: 黑咔 | 来源:发表于2020-01-08 21:30 被阅读0次

    代码示例

    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Properties;
    
    public class Properties_ {
    
        public static void main(String[] args) throws IOException {
    
            //1. 创建Properties对象
            Properties properties = new Properties();
            //2. 加载指定配置文件
            properties.load(new FileReader("src\\mysql.properties"));
            //3. 根据key 获取对应的值
            String user = properties.getProperty("user");
            String pwd = properties.getProperty("pwd");
            System.out.println("用户名=" + user);
            System.out.println("密码=" + pwd);
        }
    }
    

    相关文章

      网友评论

          本文标题:使用Properties类读取配置文件

          本文链接:https://www.haomeiwen.com/subject/mybvyctx.html