spring boot读取classpath下的json文件
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
使用@Value注解
@Value(value="classpath:default.json")
private Resource resource;
BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()));
StringBuffer message=new StringBuffer();
String line = null;
while((line = br.readLine()) != null) {
message.append(line);
}
String defaultString=message.toString();
String result=defaultString.replace("\r\n", "").replaceAll(" +", "");
System.out.println(result);
spring boot读取classpath下的json文件的更多相关文章
- 解决:java 读取 resources 下面的 json 文件
前言:java 读取 工程下的配置文件,文件类型为 json(*.json),记录一下始终读取不到 json 文件的坑.maven项目 直接上工具类代码 package com.yule.compon ...
- Spring Boot 读取 resource 下文件
支持linux下读取 import org.springframework.core.io.ClassPathResource; public byte[] getCertStream(String ...
- 读取ClassPath下resource文件的正确姿势
1.前言 为什么要写这篇文章?身为Java程序员你有没有过每次需要读取 ClassPath 下的资源文件的时候,都要去百度一下,然后看到下面的这种答案: Thread.currentThread(). ...
- Java读取classpath下的文件
写Java程序时会经常从classpath下读取文件,是时候该整理一下了,并在不断深入的过程中,陆续补充上. 现在Java project 都以maven项目居多, 比如像下面这样的一个项目结构: 编 ...
- js 读取外部的本地json文件
Javascript 读取外部的本地json文件 方案1 运行本地web服务器,提供文件服务 方案2 1.data = '[{"name" : "Ashwin" ...
- 【Azure 应用服务】App Service For Linux 部署Java Spring Boot应用后,查看日志文件时的疑惑
编写Java Spring Boot应用,通过配置logging.path路径把日志输出在指定的文件夹中. 第一步:通过VS Code创建一个空的Spring Boot项目 第二步:在applicat ...
- Spring boot 国际化自动加载资源文件问题
Spring boot 国际化自动加载资源文件问题 最近在做基于Spring boot配置的项目.中间遇到一个国际化资源加载的问题,正常来说只要在application.properties文件中定义 ...
- Spring Boot@Component注解下的类无法@Autowired的问题
title: Spring Boot@Component注解下的类无法@Autowired的问题 date: 2019-06-26 08:30:03 categories: Spring Boot t ...
- php读取目录下的所有文件
php读取目录下的所有文件 $path = './use'; $result = scanFile($path); function scanFile($path) { global $result; ...
随机推荐
- P4114 Qtree1
思路 树剖一发,注意对LCA的处理 代码 #include <cstdio> #include <algorithm> #include <cstring> usi ...
- numpy小结
<python数据科学>笔记 在线版地址:https://github.com/jakevdp/PythonDataScienceHandbook 1.常用np简写 import num ...
- OS X EI Captain 下解决 There was a problem confirming the ssl certificate 问题
参考: Problem Confirming the SSL Certificate - OSX OS X EI Captain 下解决 There was a problem confirming ...
- 【php】单例模式和工厂模式
单例模式:防止重复实例化,避免大量的new操作,减少消耗系统和内存的资源,使得有且仅有一个实例对象 header("Content-type: text/html; charset=utf- ...
- 线程demo异常处理
今天写了个线程小demo,出现了异常, 如下: Traceback (most recent call last): File "threading.py", line 1, in ...
- Pandas 基础(17) - to_datetime
这一节依然是关于时间的知识, 在平时的工作中, 有一个非常令我们恼火的就是时间的格式可以有很多种表达, 比如下面这张图, 我们看到同样是 2017年1月5日, 可以有很多种时间的格式, 我们需要先将格 ...
- Java——ping & telnet实现
ping & telnet 实现类: import org.springframework.data.web.JsonPath; import java.io.IOException; imp ...
- 用 jupyter notebook 打开 oui.txt 文件出现的问题及解决方案
问题背景:下载了2018 IEEE 最新的 oui.txt 文件.里面包含了 设备 MAC 地址的前六位对应的厂商.要做的工作是,将海量设备的 MAC 地址与 oui.txt 文件的信息比对,统计出 ...
- [redis] redis 命令
- Lua完全自学手册(图文教程)
Programming in Lua程序设计 http://book.luaer.cn/ Lua完全自学手册(图文教程) https://edu.aliyun.com/course/506/les ...