1:方式1:

public static List<String> userList;
static {
userList = new LinkedList<String>();
try {
**String filePath = TestClient.class.getClassLoader().getResource("users.txt").getPath();**
**BufferedReader reader = new BufferedReader(new FileReader(new File(filePath)));**
try {
String line = null;
while ((line = reader.readLine()) != null) {
userList.add(line);
}
} finally {
reader.close();
}
}catch (Exception e){
e.printStackTrace();
}

2:方式2:

public staitc List<String> userList;
static {
userList = new LinkedList<String>();
try {
**InputStream is = TestClient.class.getResourceAsStream("/user.txt");**
**BufferedReader reader = new BufferedReader(new InputStreamReader(is));**
try {
String line = null;
while ((line = reader.readLine()) != null) {
userList.add(line);
}
} finally {
reader.close();
}
}catch (Exception e){
e.printStackTrace();
}

3:Other Demos

    import java.io.InputStream;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle; public class PropValue {
private static String BASE_URL;
static {
ResourceBundle rb=null;
try {
InputStream inputStream = PropValue.class.getResourceAsStream("/boot.properties");
rb = new PropertyResourceBundle(inputStream);
BASE_URL=rb.getString("boot_url");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){
System.out.println(PropValue.BASE_URL);
}
}

Maven 工程读取resource下的文件的更多相关文章

  1. maven工程读取resource下配置文件

    maven工程读取resource下配置文件 在maven工程中,我们会将配置文件放到,src/main/resources   下面,例如 我们需要确认resource 下的文件 编译之后存放的位置 ...

  2. SpringBoot项目构建成jar运行后,如何正确读取resource下的文件

    SpringBoot项目构建成jar运行后,如何正确读取resource下的文件 不管你使用的是SpringBoot 1.x还是SpringBoot2.x,在开Dev环境中使用eclipse.IEAD ...

  3. Spring项目读取resource下的文件

    目录 一.前提条件 二.使用ClassPathResource类读取 2.1.Controller.service中使用ClassPathResource 2.2.单元测试使用ClassPathRes ...

  4. springboot读取resource下的文件

    public static String DEFAULT_CFGFILE = ConfigManager.class.getClassLoader().getResource("conf/s ...

  5. springboot 读取 resource 下的文件

    ClassPathResource classPathResource = new ClassPathResource("template/demo/200000168-check-resp ...

  6. SpringBoot读取Resource下文件的几种方式(十五)

    需求:提供接口下载resources目录下的模板文件,(或者读取resources下的文件)给后续批量导入数据提供模板文件. 方式一:ClassPathResource //获取模板文件:注意此处需要 ...

  7. maven工程中防止mapper.xml文件被漏掉、未加载的方法

    maven工程中防止mapper.xml文件被漏掉.未加载的方法 就是在pom.xml文件中添加以下内容 <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉. --&g ...

  8. xcode自动刷新resource下的文件

    修改resource下的lua或者ccbi文件时,xcode并不会察觉到,所以需要手动清理xcode缓存和模拟器缓存,开发效率比较低下. 通过以下步骤可以实现自动刷新resource下的文件,且无需手 ...

  9. Maven项目读取resources下文件的路径问题(getClassLoader的作用)

    读取resources下文件的方法 网上有问答如下:问: new FileInputStream("src/main/resources/all.properties") new ...

随机推荐

  1. Python 全栈开发七 面向对象

    一.编程范式 编程是程序员用特定的语法+数据结构+算法组成的代码来告诉计算机如何执行任务的过程 , 一个程序是程序员为了得到一个任务结果而编写的一组指令的集合,正所谓条条大路通罗马,实现一个任务的方式 ...

  2. gerrit设置非小组成员禁止下载代码

    对gerrit有所了解的同学,都知道gerrit 是我们常用的一个来做代码审核的工具,其中的权限管理,是一个非常重要的环节,关于每个权限的使用范围,可以参考博客https://blog.csdn.ne ...

  3. node跨域cors模块,nodejs+express跨域

    使用express写的接口,只能在内部使用,如果想要外部的服务访问,就涉及到了跨域.但是又不想用jsonp,其实有一个node模块,可以轻松实现跨域 npm install cors --save 然 ...

  4. 回车和刷新以及Ctr+F5的区别

    回车(url跳转)主要是判断本地缓存文件的Expires的有效时间,如果有效则直接使用客户端缓存 不在提交到HTTP服务器 F5 Expires设置不再起效果,只有Last-Modified/ETag ...

  5. 在屏幕拖拽3D物体移动

    3D物体的拖拽不同于2D的.因为3D物体有x,y,z当然.实际拖拽还是在XZ平面.只是多了几个转换 using UnityEngine; using System.Collections; publi ...

  6. mysql的in和not in的用法(特别注意not in结果集中不能有null)

    1. not in的结果集中出现null则查询结果为null; 例如下面sql中,含有list中null值,无法正确查询结果: SELECT COUNT(name) FROM CVE WHERE na ...

  7. vue中解决跨域问题

    方法1.后台更改header header('Access-Control-Allow-Origin:*');//允许所有来源访问 header('Access-Control-Allow-Metho ...

  8. LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏。

    问题描述:VS2010   LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏. 解决办法: 修改嵌入清单选项为否,然后重新便于创建. 参考自:htt ...

  9. UVA 11796 Dog Distance(几何)

    Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...

  10. CentOS中利用Docker安装RabbitMQ

    CentOS中利用Docker安装RabbitMQ 1.拉取镜像(带管理平台) #docker pull rabbitmq:3.7.7-management 2.启动容器: #docker run - ...