您可以用浏览器打开html文件,然后使用“文件”-“另存为”,在保存类型中选择相应项目即可。注意要是保存网页全部,会多处一个文件夹存放图片等文件,mht本来就是这样的 。
public boolean compile() {if (strWeb == null || strText == null || strFileName == null || strEncoding == null)
return false
NodeList nodes = new NodeList()
try {
Parser parser = createParser(strText)
parser.setEncoding(strEncoding)
nodes = parser.parse(null)
} catch (ParserException e)
{
e.printStackTrace()
}
try {
createMhtArchive(strText)
} catch (Exception e) {
e.printStackTrace()
return false
}
return true
}
private Parser createParser(String inputHTML) {
Lexer mLexer = new Lexer(new Page(inputHTML))
return new Parser(mLexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET))
}
private void createMhtArchive(String content) throws Exception {
MimeMultipart mp = new MimeMultipart("related")
Properties props = new Properties()
props.put("mail.smtp.host", smtp)
Session session = Session.getDefaultInstance(props, null)
MimeMessage msg = new MimeMessage(session)
msg.setHeader("X-Mailer", "Code Manager .SWT")
if (from != null) {
msg.setFrom(new InternetAddress(from))
}
if (subject != null) {
msg.setSubject(subject)
}
if (to != null) {
InternetAddress[] toAddresses = getInetAddresses(to)
msg.setRecipients(Message.RecipientType.TO, toAddresses)
}
if (cc != null) {
InternetAddress[] ccAddresses = getInetAddresses(cc)
msg.setRecipients(Message.RecipientType.CC, ccAddresses)
}
if (bcc != null) {
InternetAddress[] bccAddresses = getInetAddresses(bcc)
msg.setRecipients(Message.RecipientType.BCC, bccAddresses)
}
MimeBodyPart bp = new MimeBodyPart()
bp.setText(content, strEncoding)
bp.addHeader("Content-Type", "text/htmlcharset=" + strEncoding)
bp.addHeader("Content-Location", strWeb.toString())
mp.addBodyPart(bp)
msg.setContent
msg.writeTo(new FileOutputStream(strFileName))
System.out.print("444444444444444444444444444444444444")
}
private InternetAddress[] getInetAddresses(String emails) throws Exception {
ArrayList list = new ArrayList()
StringTokenizer tok = new StringTokenizer(emails, ",")
while (tok.hasMoreTokens()) {
list.add(tok.nextToken())
}
int count = list.size()
InternetAddress[] addresses = new InternetAddress[count]
for (int i = 0i <counti++) {
addresses[i] = new InternetAddress(list.get .toString())
}
return addresses
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)