在我看来,下面的代码 fragment 应该有效,但“mp.getBodyPart(1).getContent().toString()”返回
com.sun.mail.util.BASE64DecoderStream@44b07df8
而不是附件的内容。
public class GMailParser {
public String getParsedMessage(Message message) throws Exception {
try {
Multipart mp = (Multipart) message.getContent();
String s = mp.getBodyPart(1).getContent().toString();
if (s.contains("pattern 1")) {
return "return 1";
} else if (s.contains("pattern 2")) {
return "return 2";
}
...
最佳答案
它只是意味着 BASE64DecoderStream 类不提供自定义 toString 定义。默认的toString定义是显示类名+'@'+Hash Code,就是你看到的。
要获取 Stream 的“内容”,您需要使用 read() 方法。
关于java - 为什么我不能使用 toString 解析 javamail 附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3453997/