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. 前端学习笔记2017.6.12 HTML的结构以及xhtml、html、xml的区别

    HTML的结构 一个HTML文档可分为几个部分,如下图所示: DOCTYPE部分.head部分和body部分 DOCTYPE部分,这个很重要,可以理解为不同的DOCTYPE意味着不同的html标准,因 ...

  2. [gist]Android SHA-1

    参考:http://stackoverflow.com/questions/5980658/how-to-sha1-hash-a-string-in-android 代码:

  3. Luogu 3911 最小公倍数之和

    感觉自己被早上的名校协作体和下午的数学题虐哭了,每天为自己的菜发愁…… 发现$a_{i}$很小,开一个桶记一下每个数 出现的个数,设$c_{i} = \sum_{j = 1}^{n}(a_{j} == ...

  4. Git 之 与Github交互

    我们不可能只在一台电脑上开发,白天在公司用公司电脑,晚上在家可以用自己电脑.但是这个代码怎么让两台电脑同步呢?总不能用U盘复制粘贴.太繁琐. 这里我们就可以找个代码托管的平台,帮我们做这件事. Git ...

  5. python 爬虫之requests+日志+配置文件读取+mysql入库

    #!/usr/bin/env python # -*- coding: utf-8 -*- # 日志管理 import logging import sys reload(sys) sys.setde ...

  6. iTween插件使用

    itween插件 itween是一个动画库,作者创建它的目的就是最小的投入实现最大的产出.用它可以轻松实现各种动画,晃动,旋转,移动.褪色.上色.控制音频等. iTween原理: itween的核心是 ...

  7. GoogLeNet InceptionV2/V3/V4

    仅用作自己学习 这篇文章中我们会详细讲到Inception V2/V3/V4的发展历程以及它们的网络结构和亮点. GoogLeNet Inception V2        GoogLeNet Inc ...

  8. gRPC官方文档(概览)

    文章来自gRPC 官方文档中文版 概览 开始 欢迎进入 gRPC 的开发文档,gRPC 一开始由 google 开发,是一款语言中立.平台中立.开源的远程过程调用(RPC)系统. 本文档通过快速概述和 ...

  9. vue 用axios实现调用接口下载excel

    了解的方式有两种: 1. 用a标签,href设置为后端提供的excel接口 <a href="excel接口">导出</a> 简单方便,缺点就是当有toke ...

  10. 【bzoj1853】: [Scoi2010]幸运数字 数论-容斥原理

    [bzoj1853]: [Scoi2010]幸运数字 预处理出所有幸运数字然后容斥原理 但是幸运数字是2logn个数的 直接搞会炸 所以把成倍数的处理掉 然后发现还是会T 所以数字要从大到小处理会快很 ...