在我下面的代码中,我想从电子邮件中下载附件,然后想存储在 C 驱动器中名为 Attachment 的特定文件夹中,而不是存储在下载中,我的代码如下
String attachFiles = "";
String saveDirectory = "C://Attachment//"; // Here I want to store my attachments
if (contentType.contains("multipart")) {
Multipart multiPart = (Multipart) message.getContent();
int numberOfParts = multiPart.getCount();
for (int partCount = 0; partCount < numberOfParts; partCount++) {
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
String fileName = part.getFileName();
attachFiles += fileName + ", ";
part.saveFile(saveDirectory + File.separator + fileName);
} else {
messageContent = part.getContent().toString();
}
}
}
任何帮助将不胜感激