zoukankan      html  css  js  c++  java
  • properties工具类

    package rw.util;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.Properties;


    public class PropertiesUtils {

    /**
    * 获得src目录下的properties文件的属性
    *
    * @param url properties文件路径
    * @param property
    * @return
    */
    public static String getProperty(String url, String property) {
    Properties pro = getProperties(url);
    String proValue = (String) pro.get(property);
    return proValue;
    }

    /**
    * 根据路径获得Properties对象
    * @param url
    * @return
    */
    public static Properties getProperties(String url){
    InputStream is = null;
    BufferedReader bf = null;
    Properties pro = new Properties();
    try {
    is = PropertiesUtils.class.getClassLoader().getResourceAsStream(url);
    bf = new BufferedReader(new InputStreamReader(is, "utf-8"));
    pro.load(bf);

    }catch(Exception e){
    System.out.println(e.getStackTrace());
    }finally {
    if (is != null) {
    try {
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if (bf != null) {
    try {
    bf.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    }
    return pro;
    }

    }

  • 相关阅读:
    CSS选择器
    CSS样式与语法
    实训第二天
    初学前端
    html-路径和图像标签
    html
    JavaScript(基础)
    CSS(2)
    CSS()
    HTML(链接与表单)
  • 原文地址:https://www.cnblogs.com/adamas21/p/5066984.html
Copyright © 2011-2022 走看看