我目前正在開發一個應用程序,它從Gmail帳戶下載附件。 現在,我每次下載壓縮附件都會出錯。但是,並非全部,有些我可以無誤地檢索它。以下是例外消息:JavaMail BaseEncode64錯誤
Exception in thread "main" com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed 4 valid base64 characters but only got 1 before EOF, the 10 most recent characters were: "Q3w5ilxj2P"
通知:我可以通過gmail網絡界面下載附件。
這裏的片段:
Multipart multipart = (Multipart) message.getContent();
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
if (bodyPart.getFileName().toLowerCase().endsWith("zip") ||
bodyPart.getFileName().toLowerCase().endsWith("rar")) {
InputStream is = bodyPart.getInputStream();
File f = new File("/tmp/" + bodyPart.getFileName());
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = new byte[bodyPart.getSize()];
int bytesRead;
while ((bytesRead = is.read(buf)) != -1) {
fos.write(buf, 0, bytesRead);
}
fos.close();
}
}
}
任何人有任何想法,如何解決這個問題呢?
還有什麼運氣呢? – William 2009-11-29 18:08:42
不,還沒有。似乎。沒有人對java郵件感興趣:( – ariefbayu 2009-11-30 01:27:52