springBoot读取json文件

代码如下

import org.junit.Test;

import java.io.*;

public class JsonTest {


    @Test
    public void testMethod() {
        BufferedReader br = null;
        String path = "a.json";
        try {
            br = new BufferedReader(new InputStreamReader(JsonTest.class.getClassLoader().getResourceAsStream(path)));
            String line = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (line != null) {
                sb.append(line + "\r\n");
                line = br.readLine();
            }
            System.out.println(sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

目录结构

springBoot读取json文件_第1张图片

做个笔记,方便自己读取json到java代码中

 

你可能感兴趣的:(Java新手之路)