Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to save an attachment using javamail

843830May 8 2006 — edited Aug 30 2006
Hi all,
i wants to save the attachments of mails into database.
Iam facing an IO exception as NO CONTENT.
iam unable to read the attched file.
the inputstram.available is returning null value,and also line count is -1.but it is giving the proper size of the file and also able to access the file ame.
Will u plz anyone help me out how to solve this..
The code i did is as follows:
Multipart multipart = (Multipart)m.getContent();
	            		System.out.println("Multpart count::"+multipart.getCount());
     		            for (int z=0; z<multipart.getCount(); z++) 
 		                {
 		                  BodyPart part = multipart.getBodyPart(z);
 		                  String disposition = part.getDisposition();  
 		                  if ((disposition != null) && (disposition.equals(Part.ATTACHMENT) || (disposition.equals(Part.INLINE))))
 		                  {   
 		                	 System.out.println("Stram values::"+part.getInputStream()+"::Disposition::"+part.getDisposition());
 		                	  if(filepath != null)
 		                	  {
 		                		 String filename=filepath+"/"+ part.getFileName();  
 		                		System.out.println("filename path::"+filename);
 		                		 File file = new File(filename);  
 		                		 InputStream in=part.getInputStream();
 		                		 FileOutputStream fos = new FileOutputStream(file); 
      		           			 byte[] buf = new byte[1024];
      		           			 int c=0;
      		           			 while((c=in.read(buf)) != -1)
      		           			 {
      		           			 	fos.write(buf, 0, c);
      		           			 }
    		           			in.close();
    		           			fos.close();
 		                	  }
}
}
Plz help me yaar.thanks in advance.
regards,
chintu
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2006
Added on May 8 2006
5 comments
253 views