zoukankan      html  css  js  c++  java
  • 解析Properties文件

    /**
         * 传入需要解析的文件属性,传入文件的路径
         * @param para 需要获取的属性名称、也就是键值对中的键名称
         * @param filepath
         * @return
         */
        public static String getPara(String para,String filepath){
            InputStream is = null;
            try{
            Properties properties = new Properties();
            //接下来需要获取.properties的文件路径:具体文件放的位置看下图。不加表示在本类的同一目录下操作
            String path = Thread.currentThread().getContextClassLoader().getResource("initKey.properties").getPath();
            //然后加载该文件:
            is = new FileInputStream(path);
            properties.load(is);
            //最后你就可以get它的属性了:
            String para1=properties.getProperty(para);
            
            System.out.println(para1);
            
            return para1;
            
            }catch(Exception e){
                e.printStackTrace();
            }finally{
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                
            }
            
            return "";
            
        }

    引入包的路径

    import java.util.Properties;

    maven项目

  • 相关阅读:
    shell:读取文件的每一行内容并输出
    shell中set命令
    shell中declare命令
    MySQL MID()函数用法
    mysql的取整函数
    二分查找算法
    zookeeper安装和使用
    Redis 集群--------Redis-cluster
    ehcahe + redis 实现多级缓存
    Redis事物
  • 原文地址:https://www.cnblogs.com/guokai870510826/p/5983578.html
Copyright © 2011-2022 走看看