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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| File fic = new File(xmlDir, pdfFileName);
if (fic.exists()){
result.setStringResult(fic.getAbsolutePath());
result.setSuccess(true);
response.setContentType("application/x-download");
response.setHeader("Content-disposition", "attachment;filename=" + pdfFileName +"");
try
{
ServletOutputStream out = response.getOutputStream();
BufferedInputStream from = null;
try
{
response.setContentLength((int) fic.length());
int bufferSize = 64 * 1024;
try
{
from =
new BufferedInputStream(new FileInputStream(fic), bufferSize * 2);
byte[] bufferFile = new byte[bufferSize];
for (int i = 0;; i++)
{
int len = from.read(bufferFile);
if (len < 0)
break;
out.write(bufferFile, 0, len);
}
out.flush();
}
finally
{
try
{
from.close();
}
catch (Exception e)
{
}
try
{
out.close();
}
catch (Exception e)
{
}
}
}
catch (Exception e)
{
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
Partager