msg.setContent(mp);
File emlFile = new File(extractPath+StringFilter(m_subject+" "+mailtime)+".eml");
//File emlFile = new File(extractPath+memo.getNoteID()+".eml");
emlFile.createNewFile();
FileOutputStream outFile = new FileOutputStream(emlFile);
msg.writeTo(outFile);
outFile.close();
deleteDir(extractDir2);
} catch (MessagingException mex) {
deleteDir(extractDir2);
mex.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
recycleRes(eo);
recycleRes(body);
recycleRes(memo);
}
}
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
public static String StringFilter(String str) {
String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\]\\\\.<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
//m=m.replaceAll("\\\\","");
return m.replaceAll("").trim();
}
--------------------------------------分割线 --------------------------------------
编写高质量代码 改善Java程序的151个建议 PDF高清完整版
Java对象序列化ObjectOutputStream和ObjectInputStream示例
--------------------------------------分割线 --------------------------------------