2013-07-20 39 views
2

我被困在這裏,任何幫助將不勝感激。 我正在使用Multipart/Bodypart概念下載我的Gmail附件。 下載很好,工作正常。但在實際下載文件之前無法獲得附件大小。在下載之前以編程方式獲取gmail附件大小

下面是代碼片段:

Store store = s.getStore("imaps"); 
store.connect("imap.gmail.com", "[email protected]", "password"); 
Folder inbox = store.getFolder("Misc"); 
inbox.open(Folder.READ_ONLY); 
Message[] msgs = inbox.getMessages(); 
Multipart m=(Multipart)msgs[inbox.getMessageCount()-1].getContent(); //taking latest email 
for(int i = 0;i < m.getCount(); i++){ 
BodyPart bp = m.getBodyPart(i); 
String disposition = bp.getDisposition(); 
if(disposition!=null &&(disposition.equals("ATTACHMENT"))){ 
/*downloading code here */ 
} 
} 

如何實際下載之前獲得的附件大小?

回答

2

試試這個:

ByteArrayOutputStream os = new ByteArrayOutputStream(); 
       m.writeTo(os); 
       int bytes = os.size(); 
+0

其實我剛纔已經InputStream的一個變種利用bp.getInputStream()存儲。我如何使用該var來獲取大小? –

+0

該變量是您的總字節數。所以把它算作你的尺寸。您可以按照您的要求操作該字節。 –

+0

U無法從inputstrram獲取大小 –

相關問題