读取项目静态文件

  InputStream in = null;
        try {
            if (!isAlarming) {
                return;
            }
            in = this.getClass().getResourceAsStream("/static/email.html");
            String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DateUtil.defaultSimpleFormater));
            String s = IOUtils.toString(in, "UTF-8");
            String env = getEnvironment();

            String content = alarm.getContent().replace("\n", "
").replace("\r", "") .replace("\t", "    "); String htmlMsg = s.replace("#SYSTEM#", alarm.getSystem()).replace("#TIME#", time) .replace("#LEVEL#", alarm.getLevelHtml()).replace("#CONTENT#", content) .replace("#SUBJECT#", alarm.getSubject()) .replace("#ENVIRONMENT#", env); this.sendMail("[" + alarm.getLevel().getDesc() + "] [" + env + "] [" + alarm.getSystem() + "] " + alarm.getSubject(), htmlMsg, receivers); } catch (Exception e) { log.error(e.getMessage(), e); } finally { try { if (in != null) { in.close(); } } catch (Exception e2) { } }

 

你可能感兴趣的:(commons,common.io)