读取文件

1.得到file

String contexPath= request.getSession().getServletContext().getRealPath("/");

String filePath=contexPath+"spring"+File.separator+"400.html";

System.out.println(filePath);

File file = new File(filePath); //类路径

 

2.读取文件

public static String getFileString(File file) {
StringBuffer sb = new StringBuffer("");
try {
InputStream fileInputStream = new FileInputStream(file);
byte[] bbuf = new byte[1024];
int hasRead = 0;
while ((hasRead = fileInputStream.read(bbuf)) != -1) {
sb.append(new String(bbuf, 0, hasRead, "utf-8"));
}
fileInputStream.close();
System.out.println(sb);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}

String contexPath= request.getSession().getServletContext().getRealPath("/");String filePath=contexPath+"spring"+File.separator+"400.html";System.out.println(filePath);File file = new File(filePath); //类路径

考虑过滤掉 .replaceAll("\r|\n|\t", ""));

3. 文件 400.html

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head>
<body>
Dear #person#
<p>以下是待处理客户需求,故邮件通知;</p>
<p>为确保客户服务满意度,收到邮件请及时处理,非常感谢!</p>
<table >
<tr>
<td>时间</td>
<td>#createTime#</td>
</tr>
<tr>
<td>记录人</td>
<td>#createPerson#</td>
</tr>
<tr>
<td>来源</td>
<td>#source#</td>
</tr>
<tr>
<td>客户分类</td>
<td>#custSort#</td>
</tr>
<tr>
<td>客户类别</td>
<td>#customerCategory#</td>
</tr>
</table>

<table border=1 style="margin-top:20px;">
<tr>
<td>公司名称</td>
<td>联系人</td>
<td>职位</td>
<td>电话</td>
<td>QQ/微信号/邮件</td>
<td>服务类型</td>
<td>厂牌</td>
<td>问题描述</td>
<td>服务内容</td>
<td>项目编号</td>
<td>是否待办</td>
<td>处理人</td>
<td>处理状态 </td>
</tr>
<tr>
<td>#custName#</td>
<td>#custPersonName#</td>
<td>#dept#</td>
<td>#phone#</td>
<td>#link#</td>
<td>#serviceType#</td>
<td>#brand#</td>
<td>#callContent#</td>
<td>#logName#</td>
<td>#fprojectNo#</td>
<td>#dealFlag#</td>
<td>#processNames#</td>
<td>#processStatus# </td>
</tr>
</table>
</body>
</html>

posted @ 2018-09-27 15:46  albert_think  阅读(163)  评论(0编辑  收藏  举报