Saving attachments in directory using javamail
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   vidhya_subramaniam
Posted On:   Friday, January 24, 2003 09:25 AM

I have to code for receiving mails with attachments. I am not sure where exactly it is saving the file. My code goes like this public static void saveFile(String filename, InputStream input) throws IOException { if (filename == null) { filename = File.createTempFile("xx", ".out").getName(); } // Do no overwrite existing file File file = new File(filename); for (int i=0; file.exists(); i++) { file = new File(filename+i); } FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); BufferedInputStream bis = new BufferedInputStream(input); int aByte; while ((aByte = bis.r   More>>

I have to code for receiving mails with attachments. I am not sure where exactly it is saving the file. My code goes like this

public static void saveFile(String filename,
InputStream input) throws IOException {
if (filename == null) {
filename = File.createTempFile("xx", ".out").getName();
}
// Do no overwrite existing file
File file = new File(filename);
for (int i=0; file.exists(); i++) {
file = new File(filename+i);
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);

BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
}
bos.flush();
bos.close();
bis.close();
}

What should I give in place of 'xx'. I tried giving my local directory where I want the file to be saved but it doesnt work.

Can someone help?

Thanks,
Vidhya

   <<Less
About | Sitemap | Contact