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. 查看Nginx、PHP、Apache和MySQL的编译参数

    1.查看Nginx编译参数 [root@portal finance]# your_nginx_dir/sbin/nginx -V nginx version: nginx/ built by (Re ...

  2. k8s 容器的生命周期钩子

    钩子有两个一个容器起之前定义一个动作PostStart,容器关闭之前定义一个动作PreStop 动作可以是一个命令或http请求 示例 spec: containers: - lifecycle: p ...

  3. jquery dataTables例子

    https://datatables.net/examples/styling/bootstrap.html http://datatables.club/example/#styling http: ...

  4. python 读取excel数据并将测试结果填入Excel

    python 读取excel数据并将测试结果填入Excel 读取一个Excel中的一条数据用例,请求接口,然后返回结果并反填到excel中.过程中会生成请求回来的文本,当然还会生成一个xml文件.具体 ...

  5. centos7挂载新加4T硬盘到/home目录

    以下操作均在root环境下运行. 1.查看硬盘 # fdisk -l 发现硬盘为/dev/sdb 大小4T 2.如果此硬盘以前有过分区,则先对磁盘格式化: # mkfs -t ext4 /dev/sd ...

  6. echarts实现全国地图

    1.首先我没有按需引入echarts,我是全局引入的,所以说在node_modules中有 这个china,你只需要在你的页面引入即可 但是按需引入echarts 的 项目中node_modules中 ...

  7. VirtualBox下扩容vdi文件

    VirtualBox下扩容vdi文件 版本:VirtualBox 5.0.14 之前VirtualBox创建的虚拟机的vdi文件过小,无法满足新的实验需求,扩容vdi文件的方法如下: 比如我这里将RH ...

  8. powerdesign、navacat、ER图、uml、类图、时序图

    关于建表和生成实体以及ER图的简便方法 a:用navacat客户端生成简单的ER图,并生成建表sql,执行生成表. b:用powerdesign连接数据库,反向生成带有注释的ER图. c:用ideal ...

  9. Beta冲刺阶段5.0

    1. 提供当天站立式会议照片一张 2. 每个人的工作 (有work item 的ID) 成员 昨天已完成的工作 今天计划完成的工作 工作中遇到的困难 具体贡献 郑晓丽 首页活动详情界面的美化 实现首页 ...

  10. <2>Cocos Creator文件结构

    1.文件结构 当新建HelloWorld项目后会自动出现以下文件夹结构 ProjectName(项目文件夹名称) |------assets |------library |------local | ...