zoukankan      html  css  js  c++  java
  • Properties文件读取

    package com.googosoft.util;
    
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Iterator;
    import java.util.Properties;
    
    /**
     * @author songyan
     * @date 2020年5月27日 下午3:33:20
     * @desc Properties文件读取
     */
    public class PropertiesUtil {
        
        /**
         * 读取指定properties文件的指定属性值
         * @param propertiesFilePath
         * @param handlerClass
         * @return
         */
        public static String get(String propertiesFilePath, String key) {
            Properties prop = new Properties();
            try (InputStream in = new BufferedInputStream(new FileInputStream(propertiesFilePath));) {
                prop.load(in);
                return prop.getProperty(key);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return null;
        }
    
        /**
         * 获取指定properties文件中第一个指定属性值的属性名
         * @param propertiesFilePath
         * @param value
         * @return
         */
        public static String getFirstKeyByValue(String propertiesFilePath, String value) {
            Properties prop = new Properties();
            try (InputStream in = new BufferedInputStream(new FileInputStream(propertiesFilePath));) {
                prop.load(in);
                Iterator<String> it = prop.stringPropertyNames().iterator();
                while (it.hasNext()) {
                    String itemKey = it.next();
                    String itemValue = prop.getProperty(itemKey);
                    if (value != null && value.equals(itemValue)) {
                        return itemKey;
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return null;
        }
    }
  • 相关阅读:
    【转】利用Python将多个PDF合并为一个
    sudo配置教程
    tomcat查看并修改jvm大小
    jetty隐藏版本号教程
    weblogic为同一domain下的不同server添加不同参数
    Oracle使用expdp/impdp导出导入数据
    Windows设置.txt文件默认打开程序
    weblogic查看版本号教程
    Linux登录超时自动退出处理办法
    telnet强制中断登录
  • 原文地址:https://www.cnblogs.com/excellencesy/p/12978143.html
Copyright © 2011-2022 走看看