• java项目中读取jdbc.properties文件


    java项目中读取jdbc.properties文件

    参考于:https://www.cnblogs.com/sebastian-tyd/p/7895182.html

    tomcat下目录(resource已经build path,即实际线上yunxin.properties在WEB-INFclasses):

     

    yunxin.properties文件内容

    1 appKey = 96db945b680863b3a0bfe********
    2 appSecret = 9b52******
    3 nonce =  *****
    4 refreshURL = https://api.netease.im/nimserver/user/refreshToken.action
    5 createURL = https://api.netease.im/nimserver/user/create.action
    6 cancallback =54

    实现:

     1 public class Basic {
     2   public static Properties getPro() {
     3         Properties properties = new Properties();
     4 
     5         try {
     6             // 通过输入缓冲流进行读取配置文件
     7             InputStream InputStream = new BufferedInputStream(
     8                     new FileInputStream(new File(Basic.class.getResource("/").getPath() + "yunxin.properties")));
     9             // 加载输入流
    10             properties.load(InputStream);
    11             // 根据关键字获取value值
    12 
    13         } catch (Exception e) {
    14             e.printStackTrace();
    15         } finally {
    16             return properties;
    17         }
    18 
    19     }
    20 
    21     public static String appKey() {
    22         // 获取key对应的value值
    23         return getPro().getProperty("appKey");
    24     }
    25 
    26     public static String appSecret() {
    27         // 获取key对应的value值
    28         return getPro().getProperty("appSecret");
    29     }
    30 
    31     public static String nonce() {
    32         // 获取key对应的value值
    33         return getPro().getProperty("nonce");
    34     }
    35 
    36     public static String refreshURL() {
    37         // 获取key对应的value值
    38         return getPro().getProperty("refreshURL");
    39     }
    40 
    41     public static String createURL() {
    42         // 获取key对应的value值
    43         return getPro().getProperty("createURL");
    44     }
    45 
    46     public static int cancallback() {
    47         // 获取key对应的value值
    48         return Integer.parseInt(getPro().getProperty("cancallback"));
    49     }
    50 
    51     public static void main(String[] args) {
    52         System.out.println(cancallback());
    53     }  
    54 }
  • 相关阅读:
    Thinkphp3.2 cms之角色开发
    说几个你知道的设计模式?
    9种实现点击一个链接弹出一个小窗口的代码
    分享自己作为一个程序员的找工作经历
    网页设置锚点
    博客园网摘地址
    PHP面试总结
    简单的10秒倒计时
    PHP测试题目
    关键字搜索内容总结
  • 原文地址:https://www.cnblogs.com/carsonwuu/p/9603573.html
Copyright © 2020-2023  润新知