1. 程式人生 > >掐指一算乀缺錢

掐指一算乀缺錢

@RequestMapping(value = {"/expotFile.do"})
public void expotFile(
        @RequestParam(value = "name", required = true)String name,
        HttpServletRequest request, HttpServletResponse response) throws Exception{
        String path = AppContextManager.getAttachmentUploadPath() + File.separator + "cfets" + File.separator + "rdi";//正式上傳的目錄
        File file = new File(path +"/"+ name);
        InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
        byte[] buffer = new byte[inputStream.available()];
        inputStream.read(buffer);
        inputStream.close();
        String fileName = file.getName();
        response.reset();
        response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("UTF-8"), "ISO8859-1"));
        response.addHeader("Content-Length", "" + file.length());
        OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
        response.setContentType("application/octet-stream");
        outputStream.write(buffer);
        outputStream.flush();
        outputStream.close();

}