response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename="+new String((System.currentTimeMillis()+".log").getBytes("utf-8"),"ISO-8859-1")); OutputStream out = response.getOutputStream(); LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); String fileStr = ((RollingFileAppender) loggerContext.getLogger("ROOT").getAppender("FILE")).getFile(); File file = new File(fileStr); BufferedReader br = new BufferedReader(new FileReader(file)); String time = map.get("time"); StringUtils.isEmptyReMsg(time,"XXX"); int i=0; String line=""; while (i<3000&&(line=br.readLine())!=null){ i++; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); if(line.length()>25){ try{ LocalDateTime parse = LocalDateTime.parse(line.substring(1,24), df); LocalDateTime parse2 = LocalDateTime.parse(time, df); if(parse.compareTo(parse2)<0){ break; } }catch (Exception e){ } } out.write((line+System.getProperty("line.separator")).getBytes()); } br.close(); out.flush(); out.close();