• 读取Properties文件操作


    import java.io.InputStream;
    import java.util.Properties;
    /**
     * 读取system.properties配置文件中的参数
     */
    public class TestProperties {
        private static Properties TestProperties;
        //加载system.properties配置文件,读取文件的配置参数
        private static synchronized void loadProperties() {
            if(null==TestProperties) {
                try {
                    Properties properties=new Properties();
                    InputStream inputStream=TestProperties.class.getClassLoader().getResourceAsStream("system.properties");
                    properties.load(inputStream);
                    TestProperties=properties;
                }catch(Exception e) {
                    throw new RuntimeException("未找到配置文件");
                }
            }
        }
        //读取配置文件中的参数的值
        public void get() {
          loadProperties();
          System.out.println(TestProperties.getProperty("jdbc.driverUrl"));
          System.out.println(TestProperties.getProperty("jdbc.driverClassName"));
          System.out.println(TestProperties.getProperty("jdbc.password"));
          System.out.println(TestProperties.getProperty("jdbc.user"));
        }
        public static void main(String[] args) {
            TestProperties testProperties=new TestProperties();
            testProperties.get();
        }
    }
    jdbc.driverUrl=jdbc:mysql://localhost:3306/idcard?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.password=root
    jdbc.user=root
    一纸高中万里风,寒窗读破华堂空。 莫道长安花看尽,由来枝叶几相同?
  • 相关阅读:
    发送邮件程序
    T-SQL存储过程、游标
    GPS经纬度换算成XY坐标
    开博了
    你应该知道的 50 个 Python 单行代码
    想提升java知识的同学请进
    adb工具包使用方法
    红米note3刷安卓原生
    hadoop 使用和javaAPI
    django学习——url的name
  • 原文地址:https://www.cnblogs.com/byczyz/p/12209216.html
Copyright © 2020-2023  润新知