• 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;
        }
    }
  • 相关阅读:
    F
    E
    网上见到一同行发的隐私政策 备以后用
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    mark
    转 随机数问题
    随机不同的数
    转 基于Quick-cocos2dx 2.2.3 的动态更新实现完整篇。(打包,服务器接口,模块自更新
    字符串
    关于cmbiling.jar cocos2dx的问题
  • 原文地址:https://www.cnblogs.com/excellencesy/p/12978143.html
Copyright © 2020-2023  润新知