Javamail抛出java.lang.UnsupportedOperationException与charset =" iso-2022-cn"

时间:2018-04-17 16:21:16

标签: exception javamail

我有一个拥有以下字符集信息的eml。

Content-Type: text/plain; charset="iso-2022-cn"

虽然没有问题,但是当我将相同的eml写回磁盘时,我得到以下错误,有什么想法吗?

java.lang.UnsupportedOperationException
at sun.nio.cs.ext.ISO2022_CN.newEncoder(ISO2022_CN.java:76) ~[?:?]
at sun.nio.cs.StreamEncoder.<init>(StreamEncoder.java:176) ~[?:1.8.0_161]
at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:59) ~[?:1.8.0_161]
at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:100) ~[?:1.8.0_161]
at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:161) ~[bin/:?]
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889) ~[?:1.8.0_161]
at javax.activation.DataHandler.writeTo(DataHandler.java:317) ~[?:1.8.0_161]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1486) ~[bin/:?]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865) ~[bin/:?]
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462) ~[bin/:?]
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103) ~[bin/:?]
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889) ~[?:1.8.0_161]
at javax.activation.DataHandler.writeTo(DataHandler.java:317) ~[?:1.8.0_161]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1486) ~[bin/:?]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865) ~[bin/:?]
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462) ~[bin/:?]
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103) ~[bin/:?]
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889) ~[?:1.8.0_161]
at javax.activation.DataHandler.writeTo(DataHandler.java:317) ~[?:1.8.0_161]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1486) ~[bin/:?]
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773) ~[bin/:?]
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1749) ~[bin/:?]

1 个答案:

答案 0 :(得分:2)

这是一个不支持编码 [1] [2] 的字符集,只能解码。

因此,在写出信息时,您需要将输出标头设置为UTF-8。