String id = request.getParameter("downLoadFileId");
??String fileName = request.getParameter("fileName");
??String path = "C:\\upload\\"+id+"\\"+fileName;(存放文件的路徑)
??
??response.setHeader("Content-Disposition",? "attachment;filename="+fileName);
?
??response.setHeader("Connection",? "close");?
??response.setHeader("Content-Type",? "application/octet-stream");
??try{
???OutputStream os = response.getOutputStream(); //不加此行將只能下載文本文件.下載jpg等就會出現打不開的現象.
???FileInputStream fis = new FileInputStream(path);
???byte[] b = new byte[1024];
???int i = 0;
?
???while ( (i = fis.read(b)) > 0 )
???{
????os.write(b, 0, i);
???}
???
???fis.close();
???os.flush();
???os.close();
???}
???catch ( Exception e )
???{
????System.out.println ( "IOException." + e );
???}