zoukankan      html  css  js  c++  java
  • 读取Properties配置文件, 四种方式都可以得到webroot/WEB-INF/classes这个路径

    下面四种方式都可以得到webroot/WEB-INF/classes这个路径,有什么区别,哪种方式最好?
    String path = this.getClass().getResource("/").getPath();
    String path2 = this.getClass().getClassLoader().getResource("/").getPath();
    String path3 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
    String path4 = pageContext.getServletContext().getRealPath("/")+ "/WEB-INF/classes/ ;

    Properties config = new Properties();    
    config.load(new FileInputStream(path));
    String version=config.getProperty("version");


    个人认为第三种
    第一种有线程安全问题
    第二种在liunx下不能用是因为liunx不是用“/”而是用“/”所以没有跨平台性
    第四种使用起来不够灵活配置文件不能移动到其它文件夹下

  • 相关阅读:
    近期学习情况
    java连接数据库的两种方法总结
    近两个星期学习成果
    云笔记第一阶段总结
    圆面积
    C++计算器项目的初始部分
    C++视频课程
    A+B Format
    大一下学期的自我目标
    Kohana的请求流
  • 原文地址:https://www.cnblogs.com/wenxiu/p/5832893.html
Copyright © 2011-2022 走看看