zoukankan      html  css  js  c++  java
  • 方法总结

    1. 加载配置文件

    public static String getConfig(String fileName) {
    
            StringBuilder sb = new StringBuilder();
            
            InputStream in = null;
            try {
                
                // 获取当前jar包所在路径
                String path = ConfigLoader.class.getProtectionDomain().getCodeSource().getLocation().toString();
                int begin = path.indexOf(":")+1;
                int end = path.lastIndexOf("/")+1;
                String userDir = path.substring(begin,end);
                
                File confInDir = new File(userDir + File.separator + fileName);
                URL confInClassPath = ConfigLoader.class.getResource("/" + fileName);
                
    // 普通配置文件获取
    if(confInDir.exists()){ System.out.println("Load Config File:"+confInDir); in = new FileInputStream(confInDir); BufferedReader reader = new BufferedReader(new InputStreamReader(in,"UTF-8")); String line = null; while((line=reader.readLine())!=null){ sb.append(line).append(' '); } reader.close(); }else if(null != confInClassPath){
    // web 服务配置文件获取class目录下 in
    = ConfigLoader.class.getResourceAsStream("/" + fileName); BufferedReader reader = new BufferedReader(new InputStreamReader(in,"UTF-8")); String line = null; while((line=reader.readLine())!=null){ sb.append(line).append(' '); } reader.close(); } } catch (IOException e) { e.printStackTrace(); } finally { if(null != in){ try { in.close(); } catch (IOException e) { } } } return sb.toString(); }
  • 相关阅读:
    Luogu P1169 [ZJOI2007]棋盘制作 及悬线法浅谈
    P4338 [ZJOI2018]历史 P3703 [SDOI2017]树点涂色 题解
    多省联考2020游记
    min_25筛基础
    斯特林数、贝尔数与伯努利数基础
    后缀数组笔记
    分治FFT学习笔记
    多项式运算表
    基本积分公式表
    THUWC2019游记
  • 原文地址:https://www.cnblogs.com/Jtianlin/p/4555068.html
Copyright © 2011-2022 走看看