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. 关于bjam编译自己模块出错的问题

    将这个目录下C:\Users\Regubed的user-config.jam改为下面内容 # MSVC configurationusing msvc : 9.0 ; # Python configu ...

  2. Cocos Creator scrollview添加事件的两种方法

    scrollview添加事件 方法一这种方法添加的事件回调和使用编辑器添加的事件回调是一样的,通过代码添加, 你需要首先构造一个 cc.Component.EventHandler 对象,然后设置好对 ...

  3. Selenium基础知识(二)鼠标操作

    一.鼠标操作 这个需要使用webdriver下的ActionChains类,这个类是操作鼠标操作的: from selenium.webdriver import ActionChains 鼠标操作可 ...

  4. UGUI之Scrollbar使用

    这个效果主要用到了3个组件(对象): 1:Scrollbar对象  滚动条 2:Scroll Rect组件  让对象具有滑动效果 3:Mask组件  遮罩层.把多余的部分隐藏不显示 Scrollbar ...

  5. C# 5.0五大新特性

    第一:绑定运算符,:=: 这个只是简化了数据绑定,跟ASP.NET MVC3不断改进一样,其实不是什么亮点改进. comboBox1.Text :=: textBox1.Text; //将文本框的内容 ...

  6. hbase-java-api001

    package api; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfig ...

  7. SQL 跟据出生日期求年龄

    最近做项目时遇到一个问题. 跟据人员的生日与当前日期进行比较求出该人员实际年龄.这个看上去比较简单的问题,其实不细心去看也会有很多问题. 先看第一种: 一张人员信息表里有一人生日(Birthday)列 ...

  8. Vue系列之 => 使用第三方animated.css动画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. golang linux安装

    go在linux下的安装: [root@localhost src]# wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.t ...

  10. Sitecore 9有什么新功能

    在这个新版本中有很多值得爱的东西.每个人都会有自己喜欢的新功能,但是,我想与你分享一些地雷: xConnect 正如我们在Sitecore的官方Sitecore 9新闻稿中所见的那样,“新的xConn ...