zoukankan      html  css  js  c++  java
  • Java读取properties文件数据

    package com.it.test;
    
    import java.io.IOException;
    import java.util.Properties;
    
    import org.springframework.core.io.support.PropertiesLoaderUtils;
    
    /**
     * 
     * 使用的版本为:spring-core-4.2.5.RELEASE.jar
     * @author it_zhaojie
     *
     */
    public class Demo2 {
        public static void main(String[] args) {
            Properties properties = getProperties();
            String property = properties.getProperty("jdbc.password");
            System.out.println(property);
        }
    
        public static Properties getProperties() {
            Properties prop= null;
            try {
                prop = PropertiesLoaderUtils.loadAllProperties("jdbc.properties");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return prop;
        }
    }

     2.

    import java.util.ResourceBundle;
    
        public static void main(String[] args) {
            ResourceBundle resourceBundle = ResourceBundle.getBundle("test-deacy");
            String url = resourceBundle.getString("url");
            String username = resourceBundle.getString("user");
            String password = resourceBundle.getString("password");
        }

     3.

    public class Demo1 {
        public static void main(String[] args) {
            Properties properties = System.getProperties();
            String string = getString("url");
            System.out.println(string);
        }
    
        private static String getString(String key) {
            return ResourceBundle.getBundle("test").getString(key);
        }
    }
  • 相关阅读:
    GO 爬虫图片相关
    GO 爬虫链接
    Redis使用
    HTTP请求
    lris框架基础案例
    UDP通信功能
    C++随机
    matplotlib显示指数部分的负号
    使用opencv-python读取中文路径图片
    pytorch模型可视化,torchviz,tensorboardX,文本方式
  • 原文地址:https://www.cnblogs.com/Jack-zhao/p/13926611.html
Copyright © 2011-2022 走看看