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