public static void addContent(String file,String content) {
FileWriter fw = null;
try {
File f=new File(file);
fw = new FileWriter(f, true);
} catch (IOException e) {
e.printStackTrace();
}
PrintWriter pw = new PrintWriter(fw);
pw.println(content);
pw.flush();
try {
fw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void addContent2(String file, String conent) {
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file, true)));
out.write(conent + "\r\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@ResponseBody
@RequestMapping(value = "/crashLog",method = RequestMethod.POST)
public Result crashLog(HttpServletRequest request, HttpServletResponse response) throws IOException {
JSONObject params = JSONObject.parseObject(RequestUtils.getBody(request));
FileUtil.addContent2("E:\\app.2021-11-04.log",params.toJSONString());
return Result.ok(params);
}