类的反射及xml文件的解析

 

 

类的反射

 xml文件的解析

 

.properties||.xml配置文件的创建及读取内容

//创建对象
        Properties properties = new Properties();
        //存储
        properties.setProperty("driver", "com.mysql.jdbc.Driver");
        properties.setProperty("url", "jdbc:mysql://localhost:3306/userdb");
        properties.setProperty("user", "root");
        properties.setProperty("password", "123456");

        //存储到绝对路径盘符
        properties.store(new FileOutputStream(new File("e://home/soldier/SOLDIER/idea_project/Order/jdbc.properties")), "db配置");
        properties.storeToXML(new FileOutputStream(new File("e://home/soldier/SOLDIER/idea_project/Order/c3p0.xml")), "数据库连接池");
        //使用相对路径-->当前工程
        properties.store(new FileOutputStream(new File("jdbc.properties")), "db配置");
        properties.storeToXML(new FileOutputStream(new File("c3p0.xml")), "数据库连接池");
        //使用相对路径-->当前工程下的xxx
        properties.store(new FileOutputStream(new File("src/com/soldier/db/jdbc.properties")), "db配置");

        //读取绝对路径
        properties.load(new FileReader("e://home/soldier/SOLDIER/idea_project/Order/jdbc.properties"));
        //使用相对路径-->当前工程
        properties.load(new FileReader("jdbc.properties"));
        //使用相对路径-->当前工程下的xxx
        properties.load(new FileReader(new File("src/com/soldier/db/jdbc.properties")));

        //如果没有就输出后面的默认值
        System.out.println(properties.getProperty("user", "null"));

 

转载于:https://www.cnblogs.com/HuangJie-sol/p/10658401.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值