1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
try
{
File f = new File("C:/"+photo);
if(nomcv.toLowerCase().endsWith("jpg")) response.setContentType("image/jpeg");
else if(nomcv.toLowerCase().endsWith("gif")) response.setContentType("image/gif");
else if(nomcv.toLowerCase().endsWith("bmp")) response.setContentType("image/bmp");
else if(nomcv.toLowerCase().endsWith("png")) response.setContentType("image/png");
response.setHeader("Content-Disposition",
"attachment; filename=\""+nphoto+"\";");
response.setContentLength((int)f.length());
OutputStream os = response.getOutputStream();
FileInputStream stream = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(stream);
InputStream is = new BufferedInputStream(bis);
int count;
byte buf[] = new byte[4096];
while ((count = is.read(buf)) > -1)
{
os.write(buf, 0, count);
}
is.close();
os.close();
}catch (Exception ex){ ex.printStackTrace();}
return null; |