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文件的更多相关文章

  1. 解决:java 读取 resources 下面的 json 文件

    前言:java 读取 工程下的配置文件,文件类型为 json(*.json),记录一下始终读取不到 json 文件的坑.maven项目 直接上工具类代码 package com.yule.compon ...

  2. Spring Boot 读取 resource 下文件

    支持linux下读取 import org.springframework.core.io.ClassPathResource; public byte[] getCertStream(String ...

  3. 读取ClassPath下resource文件的正确姿势

    1.前言 为什么要写这篇文章?身为Java程序员你有没有过每次需要读取 ClassPath 下的资源文件的时候,都要去百度一下,然后看到下面的这种答案: Thread.currentThread(). ...

  4. Java读取classpath下的文件

    写Java程序时会经常从classpath下读取文件,是时候该整理一下了,并在不断深入的过程中,陆续补充上. 现在Java project 都以maven项目居多, 比如像下面这样的一个项目结构: 编 ...

  5. js 读取外部的本地json文件

    Javascript 读取外部的本地json文件 方案1 运行本地web服务器,提供文件服务 方案2 1.data = '[{"name" : "Ashwin" ...

  6. 【Azure 应用服务】App Service For Linux 部署Java Spring Boot应用后,查看日志文件时的疑惑

    编写Java Spring Boot应用,通过配置logging.path路径把日志输出在指定的文件夹中. 第一步:通过VS Code创建一个空的Spring Boot项目 第二步:在applicat ...

  7. Spring boot 国际化自动加载资源文件问题

    Spring boot 国际化自动加载资源文件问题 最近在做基于Spring boot配置的项目.中间遇到一个国际化资源加载的问题,正常来说只要在application.properties文件中定义 ...

  8. Spring Boot@Component注解下的类无法@Autowired的问题

    title: Spring Boot@Component注解下的类无法@Autowired的问题 date: 2019-06-26 08:30:03 categories: Spring Boot t ...

  9. php读取目录下的所有文件

    php读取目录下的所有文件 $path = './use'; $result = scanFile($path); function scanFile($path) { global $result; ...

随机推荐

  1. JS经典面试题汉诺塔

    我爱撸码,撸码使我感到快乐!大家好我是Counter.今天给大家分享的是利用JS将汉诺塔原理实现出来,其实主要是考察一个递归的思想,复杂的问题简单化,汉诺塔应该都知道吧,具体的游戏规则,可以百度查查, ...

  2. tree与GridView交互

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OgGridView.asp ...

  3. [FJOI2018]领导集团问题 mulitset合并

    P4577 [FJOI2018]领导集团问题 链接 luogu bzoj 他是个重题 bzoj4919: [Lydsy1706月赛]大根堆 代码改改就过了 思路 求树上的lis,要好好读题目的!!! ...

  4. Java 学习笔记- classpath classpath*

    转自:https://blog.csdn.net/javaloveiphone/article/details/51994268 1.src不是classpath, WEB-INF/classes,l ...

  5. 微信小程序云开发更换云开发环境

    小程序云开发环境初始化默认是第一个环境,但是我们可以指定环境id //app.js App({ onLaunch: function () { if (!wx.cloud) { console.err ...

  6. SQL server中如何按照某一字段中的分割符将记录拆成多条

    现需要将上结果转换为下结果 上结果查询语句:SELECT TOP 1 id,domain FROM dbo.SimpleTask 下结果转换语句:SELECT  a.Id,b.domain FROM ...

  7. java.io.IOException: Attempted read from closed stream

    前言: 代码如下,执行的时候提示"java.io.IOException: Attempted read from closed stream." public static JS ...

  8. H5外包团队 H5开发微信APP的优势有哪些

    H5外包团队 H5开发微信APP的优势有哪些

  9. Oracle配置SQL空间操作要点说明

    前面配置PL/SQL直接通过SQL查询SDE空间数据库,网上已有诸多示例, 常见问题如下: ORA-06520: PL/SQL: 加载外部库时出错ORA-06522: Unable to load D ...

  10. python实现将base64编码的图片下载到本地

    # -*- coding:utf-8 -*- #!python3 import os import base64 sss ="""base64的编码"" ...