In this situation you can do this: 
size = multipart.getBodyPart(i).
    getInputStream().available();
[Manager Note: This works perfectly for text (7-bit) attachments. In the case of binary attachments, they will be encoded so the stream size will be slightly larger.] 

解决方案 »

  1.   

    The encoded form of the file is expanded by 37% for UU encoding and by 35% for base64 encoding (3 bytes become 4 plus control information). 
    size=bodyPart.getInputStream().available()*0.65; should therefore be pretty close to the real size
      

  2.   

    Get the current Date and Time
    import java.util.*;public class Now {public static void  main(String arg[]) {
        /* 
        ** on some JDK, the default TimeZone is wrong
        ** we must set the TimeZone manually!!!
        **   Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));
        */
        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
        
        String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        java.text.SimpleDateFormat sdf = 
              new java.text.SimpleDateFormat(DATE_FORMAT);
        /*
        ** on some JDK, the default TimeZone is wrong
        ** we must set the TimeZone manually!!!
        **     sdf.setTimeZone(TimeZone.getTimeZone("EST"));
        */
        sdf.setTimeZone(TimeZone.getDefault());          
              
        System.out.println("Now : " + sdf.format(cal.getTime()));
        }
    }
     
    Here some formatting possibilities available through the SimpleDateFormat class.
    Thanks to T. Guirado for the tip. import java.util.*;
    import java.text.*;public class ShowToday {
      public static void main(String args[]) {
         ShowToday st = new ShowToday();
         st.demo();
         }
      public void demo() {   
         System.out.println(easyDateFormat("dd MMMMM yyyy"));
         System.out.println(easyDateFormat("yyyyMMdd"));
         System.out.println(easyDateFormat("dd.MM.yy"));
         System.out.println(easyDateFormat("MM/dd/yy"));
         System.out.println(easyDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z"));
         System.out.println(easyDateFormat("EEE, MMM d, ''yy"));
         System.out.println(easyDateFormat("h:mm a"));
         System.out.println(easyDateFormat("H:mm:ss:SSS"));
         System.out.println(easyDateFormat("K:mm a,z"));
         System.out.println(easyDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa"));
         }  public String easyDateFormat (String format) {
        Date today = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        String datenewformat = formatter.format(today);
        return  datenewformat;
        }
      }
     
      

  3.   

    java.util.Date date = m.getSentDate();
    java.text.SimpleDateFormat formatter =
    new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String dateString = formatter.format(date);