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. 使用ffmpeg转换视频格式

    命令: ffmpeg -i infile -ab 128 -acodec libmp3lame -ac 1 -ar 22050 -r 29.97 -qscale 6 -y outfile   说明: ...

  2. mac 彻底卸载Paragon NTFS

    之前安装了paragon NTFS,试用期过了就卸载了,但是每天还是会提示“试用期已到期”,看着很烦. 百度了一下,发现网上的版本可能比较老了,和我的情况不太一样,但道理应该是一样的. 彻底删除方法: ...

  3. IFC—IfcProduct实体继承框架

  4. ZROI2018提高day5t3

    传送门 分析我们可以根据性质将这个序列构造成一个环:0,a[1~n],0,a[n~1] 这中间的0是为了起间隔作用的. 我们又知道b[i]=a[i-1]^a[i+1] c[i]=b[i-1]^b[i+ ...

  5. Luogu 4867 Gty的二逼妹子序列

    BZOJ3809,是权限题. 我永远喜欢莫队. 先莫队一下移下左右指针,然后用一个数据结构维护一下区间$[a, b]$中的颜色的值,跟着指针移动一起修改修改,每一次$query$的时候就相当于查询一下 ...

  6. 树莓派研究笔记(5)-- FM网络收音机

    1. 安装mpc sudo apt-get install mpd mpc 2.添加流.注意,这里有个坑,如果下面这个地址不能用,那么就无法测试了.建议先下载一个龙卷风或者酷狗网络收音机,然后添加地址 ...

  7. 【Arcgis for android】程序运行出错原因分析及解决(超详细)

    查看项目下是否有libs文件夹,正常情况下其中应该有 如果没有,在项目上右键 ->arcgis tools->convert to arcgis android project 排除了上述 ...

  8. MVC Areas

    ASP.NET MVC中,是依靠某些文件夹以及类的固定命名规则去组织model实体层,views视图层和控制层的.如果是大规模的应用程序,经常会由不同功能的模块组成,而每个功能模块都由MVC中的三层所 ...

  9. 利用python下载视频

    我们知道,有些网页上的视频,没有下载的按钮,并且有些视频需要付费下载,很多同学因此很苦恼.不怕,有问题找我,我试试用程序员的方式通俗易懂教会大家. 1.你先下载一个Python,不会下载的同学可以看这 ...

  10. NSPoint 位置

    前言 结构体,这个结构体用来表示事物的一个坐标点. typedef CGPoint NSPoint; struct CGPoint { CGFloat x; CGFloat y; }; typedef ...