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);

上一篇:学习WebSocket(二):使用Spring WebSocket做一个简单聊天室


下一篇:Hash算法原理的简单分析