现在的位置: 首页 > 综合 > 正文

java download file

2013年11月04日 ⁄ 综合 ⁄ 共 564字 ⁄ 字号 评论关闭

    File file = new File("G:\\dddd.txt");
    response.reset();
    InputStream fis = new BufferedInputStream(new FileInputStream(file));
    byte[] buffer = new byte[fis.available()];
    fis.read(buffer);
    fis.close();
     response.addHeader("Content-Disposition", "attachment;filename=" + new String(file.getName().getBytes()));
     response.addHeader("Content-Length", "" + file.length());
     OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
     response.setContentType("application/octet-stream");
     toClient.write(buffer);
     toClient.flush();
     toClient.close();

抱歉!评论已关闭.