String p = this.getClass().getClassLoader().getResource(readPath).getPath();
InputStream in = this.getClass().getClassLoader().getResourceAsStream(readPath);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String content = FileUtil.readJsonFile(reader);
工具类
/**
* 读取json文件,返回json串
* @return
*/
public static String readJsonFile(Reader reader) {
String jsonStr = "";
try {
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
reader.close();
jsonStr = sb.toString();
return jsonStr;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}