0
我有要求發送不同的xls文件到不同的電子郵件。 所以我創建了一個循環,其中我執行兩個動作以循環方式發送郵件中的文件
1)在臨時 2)武官文件的創建這個文件,以郵件並跨越發送。
我的問題是文件創建成功,但我得到空白文件沒有數據在xls。
我的代碼生成文件如下,
//in a for loop
fos = new FileOutputStream(path1);
wb.write(fos); //I think writing is in progress and while file is sent in mail hence getting blank
destination = new File(path1);
InternetAddress to = null;
to = new InternetAddress("[email protected]",StringPool.BLANK);
MailMessage message=new MailMessage(to,to, "temp", createEmailBody(email,numberOfuser), true);
message.addFileAttachment(destination);
MailServiceUtil.sendEmail(message);
我真的沒有看到你給fos添加任何東西,所以......你期望什麼? – Stultuske
您至少需要關閉流。這應該將所有數據清空到底層文件系統。 – npinti