मैं ज़िप फ़ाइल अटैचमेंट के साथ ईमेल भेजना चाहता हूं .. मैं बाइटएरे ऑटपुटस्ट्रीम का उपयोग करके भौतिक स्थान पर सहेजे बिना पीडीएफ फाइलों को भेजने में सक्षम हूं। लेकिन जब मैं उन फाइलों को ज़िप करने का प्रयास करता हूं तो इसे भेजना इसे काम नहीं करता है। यह अपवाद अवैध लगाव देता है।भौतिक स्थान पर इसे बनाए बिना ज़िप फ़ाइल कैसे भेजें?
नीचे कोड है जिसे मैंने ज़िप बनाने के लिए लिखा है।
private MimeBodyPart zipAttachment(List<ByteArrayOutputStream> attachmentList, List<String> reportFileNames)
{
MimeBodyPart messageBodyPart = null;
try
{
// File file = File.createTempFile("Reports.zip",".tmp");
// FileOutputStream fout = new FileOutputStream(file);
ByteArrayOutputStream bout = new ByteArrayOutputStream(attachmentList.size());
ZipOutputStream zos = new ZipOutputStream(bout);
ZipEntry entry;
for(int i = 0; i < attachmentList.size(); i++)
{
ByteArrayOutputStream attachmentFile = attachmentList.get(i);
byte[] bytes = attachmentFile.toByteArray();
entry = new ZipEntry(reportFileNames.get(i));
entry.setSize(bytes.length);
zos.putNextEntry(entry);
zos.write(bytes);
}
messageBodyPart = new MimeBodyPart();
DataSource source = new ByteArrayDataSource(bout.toByteArray(), "application/zip");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("Reports.zip");
}
catch(Exception e)
{
// TODO: handle exception
}
return messageBodyPart;
}
क्या आप स्टैकट्रैक जोड़ सकते हैं? –