1. 程式人生 > >file 附件形式下載檔案

file 附件形式下載檔案

        // 以流的形式下載檔案。         File f = new File(path);         if (!f.exists()) {             response.sendError(404, "File not found!");             return;         }         BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));         byte[] buf = new byte[1024];         int len = 0;         response.reset();          response.setContentType("application/x-msdownload");         String filename=URLEncoder.encode(map.get("mm")+"知識系統訪問量統計月報報表.doc","UTF-8");         response.setHeader("Content-Disposition", "attachment; filename="+filename);         OutputStream out = response.getOutputStream();         while ((len = br.read(buf)) > 0)             out.write(buf, 0, len);         br.close();         out.close();