Tôi hiện đang phát triển một ứng dụng tải xuống tệp đính kèm từ tài khoản gmail. Ngay bây giờ, tôi gặp lỗi khi tải xuống tệp đính kèm đã nén. Nhưng, không phải tất cả, một số tôi có thể lấy nó mà không có lỗi. Đây là thông báo Ngoại lệ:Lỗi 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"
FYI: Tôi có thể tải xuống tệp đính kèm qua giao diện web gmail.
Sau đây là đoạn:
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();
}
}
}
Bất cứ ai có ý tưởng, làm thế nào để làm việc xung quanh vấn đề này?
Có may mắn với điều này chưa? – William
không, chưa. Có vẻ như. không ai quan tâm đến thư java: ( – ariefbayu