Java 读取文件的内容

Java 读取文件的内容

1) CLASS_NAME: 换成自己真实的类名

2) /page/test.json: 换成自己真实的page

3) FileUtils: 来自于org.apache.commons.io.FileUtils(org.apache.commons)

File f = new File(Thread.currentThread().getContextClassLoader().getResource("").getPath());
String basePath = f.getPath().replace(File.separator + "WEB-INF" + File.separator + "classes" + "", "");
File file = new File(basePath + "/page/test.json");
String fileStr= FileUtils.readFileToString(file);
System.out.println("fileStr: " + fileStr);
原文地址:https://www.cnblogs.com/cobble19/p/6508743.html