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;
    }

    }

  • 相关阅读:
    安装cifs 访问windows的共享文件
    创建swap文件
    linxu 网路的一些命令
    database mysql
    __alloc_pages
    firefox tips
    关于文件的BOM头
    java实现跳表
    java中如何优雅的停止一个线程
    java中Thread启动流程分析
  • 原文地址:https://www.cnblogs.com/adamas21/p/5066984.html
Copyright © 2011-2022 走看看