html 转 mht

html-css021

html 转 mht,第1张

很简单,不需要软件也可以。

您可以用浏览器打开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

}

MHT文件是微软推出的一种保存HTML文件的格式。可以将HTML页面以及页面中连接的图片文件保存到一个MHT格式的文件中,便于使用和保存。具体制作方法如下:

依次点击“工具→转换*.htm为*.mht”,

然后选择相应的htm文件,单击“开始转换”即可。