查找邮件附件大小 [英] Find email attachment size
本文介绍了查找邮件附件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,我附加一个文件作为电子邮件的附件。我也尝试找到bodypart的大小(在这种情况下的附件),但它返回我-1。我在哪里出错?
I have the following code, where I attach a file as an attachment to a email. I also try to find the size of bodypart(attachment in this case) but it returns me -1. Where am I going wrong ?
mBP = new MimeBodyPart();
DataSource source = new FileDataSource(fileName);
mBP.setDataHandler(new DataHandler(source));
content.addBodyPart(mBP);
String attachmentSize = mBP.getSize()+"Bytes";
即使附件正确发送,它的大小返回为-1Bytes。
Even though the attachment gets correctly sent, it returns size as -1Bytes.
推荐答案
没有办法从getSize()方法中获得确切的附件大小。它近似于实际大小的60%,因为该方法忽略任何编码的内容。唯一的方法是读取内容作为字节来计算大小。
There is no way you get the exact attachment size from getSize() method. It approximates to 60% of actual size as the method ignores any encoded content. The only way is to read the contents as bytes to figure out the size.
这篇关于查找邮件附件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文