gpt4 book ai didi

java - 为什么我不能使用 toString 解析 javamail 附件?

转载 作者:行者123 更新时间:2023-11-29 04:01:11 34 4
gpt4 key购买 nike

在我看来,下面的代码 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com