try (InputStream is = getClass().getResourceAsStream("/test.properties")) {
Properties properties = new Properties();
properties.load(is);
ps=new PropertiesPropertySource("main", properties);
} catch (IOException e) {
log.error("Something went wrong", e);
}
 private String getPomPerpertiesPath() {
String classPath = getClass().getClassLoader().getResource("").getPath();
String aString = "classes/";
String targetPath = classPath.substring(0, classPath.lastIndexOf(aString));
StringBuilder sb = new StringBuilder();
sb.append(targetPath).append("maven-archiver/pom.properties");
return sb.toString();
}*/
  private Properties getProperties(InputStream is) throws IOException {
Properties properties = new Properties();
properties.load(is);
log.info("All defined properties: {}", properties);
return properties;
}
  private Properties getProperties(String fileName) throws IOException {
try (InputStream is = new FileInputStream(new File(fileName))) {
Properties properties = new Properties();
properties.load(is);
log.info("All defined properties: {}", properties);
return properties;
}
 System.out.println(getClass().getClassLoader().getResource(""));
System.out.println(getClass().getClassLoader().getResource("").getPath());
System.out.println(getClass().getResource(""));
System.out.println(getClass().getResource("").getPath()); file:/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/
/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/
file:/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/com/citi/simpliciti/tempest/report/
/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/com/citi/simpliciti/tempest/report/ https://blog.csdn.net/wws921104/article/details/72637050/
http://riddickbryant.iteye.com/blog/436693

getResourceAsStream properties的更多相关文章

  1. java读取.properties文件

    在web开发过程中,有些配置要保存到properties文件里,本章将给出一个工具类,用来方便读取properties文件. 案例: 1:config.properties文件 name=\u843D ...

  2. properties配置文件的读取和写入

    /** * 类名:PropertiesUtil * 功能:提供对properties配置文件的读取和写入 * @author ChengTao */package com.xy.xyd.rest.bi ...

  3. properties文件中中文不能显示或者中文乱码

    1.properties 文件中文乱码问题 鼠标“右击”文件 => Resource => Text file encoding => UTF-8 2.properties 文件解析 ...

  4. getResource()和getResourceAsStream以及路径问题【转】【补】

    一 getResource 用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大常最经常用的,就是用JAVA的File类,如要取得c:/test.txt文件,就 ...

  5. Java中获取包含变量的配置文件config.properties内容

    应用场景 有些时候项目中会用到很多路径,并且很可能多个路径在同一个根目录下,那为了方便配置的修改,达到只修改根目录即可达到一改全改的效果,此时就会想到要是有变量就好了: 另外有时候路径中的文件名是不确 ...

  6. Java读取properties配置文件时,中文乱码解决方法

    public static String getConfig(String key) { Properties pros = new Properties(); String value = &quo ...

  7. Java项目中读取properties文件,以及六种获取路径的方法

    下面1-4的内容是网上收集的相关知识,总结来说,就是如下几个知识点: 最常用读取properties文件的方法 InputStream in = getClass().getResourceAsStr ...

  8. Java中Properties配置文件读取

    以下实践的是Properties配置文件的基本操作方法.像spring使用xml做依赖注入时,这个配置文件起到非常实用的作用. 一.格式规范 参考wiki百科的格式简介:https://zh.wiki ...

  9. properties文件的加载方式

    下面1-4的内容是网上收集的相关知识,总结来说,就是如下几个知识点: 最常用读取properties文件的方法 InputStream in = getClass().getResourceAsStr ...

随机推荐

  1. android-auto-scroll-view-pager (无限广告轮播图)

    github 地址: https://github.com/Trinea/android-auto-scroll-view-pager Gradle: compile ('cn.trinea.andr ...

  2. SpringMVC_01 SpringMVC五大组件、SpringMVC编程步骤(不使用注解进行配置)、SpringMVC编程步骤(利用注解进行配置)、参数获取、响应数据

    1 什么是SpringMVC 是一个mvc框架,用来简化基于mvc架构的web应用程序的 开发. 2 SpringMVC五大组件 DispatcherServlet (前端控制器) HanlderMa ...

  3. ROS Learning-003 beginner_Tutorials 创建ROS工作空间

    ROS Indigo beginner_Tutorials-02 创建ROS工作空间 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04. ...

  4. tr td th是什么的缩写

    tr是 table row 表格的行 td是table data th是table heading表格标题 ,一般表格第一行的数据都是table heading

  5. Node.js 介绍及学习

    Node.js => 简单来理解,就是指运行在服务器端的JavaScript.  Node.js 是一个基于Chrome JavaScript运行时建立的一个平台 Node.js是一个事件驱动I ...

  6. Socket编程--TCP服务端注意事项

    僵尸进程处理 僵尸进程和孤儿进程: 基本概念:我们知道在unix/linux中,正常情况下,子进程是通过父进程创建的,子进程在创建新的进程.子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预 ...

  7. 自己封装一个MySignal函数,方便以后直接copy.

    传统的signal可能会有信号未决或者信号重入或多或少的问题,毕竟这个函数已经很多年了. 所以推荐使用sigaction函数,但是sigaction函数相对signal较为复杂,而且每次要写一大堆.因 ...

  8. JVM各区域的用途

    程序计数器 用于给字节码解释器来选取吓一跳需要执行的字节码指令.每个线程有一个独立的程序计数器去,且各个线程之间互不影响.如果线程正在执行一个Java方法,这个计数器记录的是正在执行的虚拟机字节码指令 ...

  9. c# ftp创建文件(非上传文件)

    c#  ftp创建文件(非上传文件) 一.奇葩的故事: 今天项目中遇到这么个奇葩的问题,ftp文件传输完成后要在ftp目录下另一个文件夹下创建对应的空文件,听说是为了文件的完整性,既然这么说,那么就必 ...

  10. InnoDB记录压缩及使用分析

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 这篇文章,源于RDS组内的一次饭后闲聊,两位小伙伴在探讨InnoDB启用压缩后的种种,比如在磁盘上是怎么存放 ...