zoukankan      html  css  js  c++  java
  • Websphere中获取项目下.properties路径

    一:如果容器为Websphere,那下面为红色的地方不能加"/",如果为tomcat,则加上"/",

    Java代码  收藏代码
    1. String  path = this.class.getResource("").getPath()+"config.properties";  
    2.   
    3. Properties properties= new Properties();  
    4.   
    5. properties.load(new FileInputStream(new File(path )));  

    如果你的config.properties在某个包下面,则把包同时带上,如:config.properties在com.df.util包下,则为:

    Java代码  收藏代码
    1. String  path = this.class.getResource("").getPath()+"com/df/util/config.properties";  
    2.   
    3. Properties properties= new Properties();  
    4.   
    5. properties.load(new FileInputStream(new File(path )));  

    二:如果你的项目中用到了spring,那么也可这样获取,

    Java代码  收藏代码
    1. import org.springframework.core.io.Resource;  
    2.   
    3. import org.springframework.core.io.ClassPathResource;  
    4.   
    5. Resource resource = new ClassPathResource("config.properties");  //直接读取src下的,位于class文件之下
    6.   
    7. Properties  properties= new Properties();  
    8.   
    9. InputStream in = resource.getInputStream();  
    10.   
    11. properties.load(in);  

      

  • 相关阅读:
    SDK安装教程
    appscan下载
    app测试-兼容性测试与云测试技术
    app测试之耗电量测试
    App测试1-App测试概述
    app测试2--monkey稳定性测试
    app测试1--常用adb命令
    常用dos命令
    jmeter(二)脚本录制
    jmeter基础介绍
  • 原文地址:https://www.cnblogs.com/zqyanywn/p/6908650.html
Copyright © 2011-2022 走看看