日期:2014-05-16 浏览次数:20350 次
<iframe src="fileName" name="realName%" id="showFileId" width="100%" height="100%"></iframe>
/** * @param response response对象 * @param fullName 文件全路径名称 * @param disName 下载的显示文件 * @param downType 下载类型 attachment(打开需要两次), file(类似inline) */ File dbFile = new File(fullName); FileInputStream fileIn = new FileInputStream(dbFile); String contentType; contentType = "application/msword"; response.setContentType(contentType); response.setHeader("Content-Disposition", " filename=report.xls"); StringBuffer header = null; if (downType != null && !"".equals(downType)) { header = new StringBuffer(downType + "; filename="); } else { header = new StringBuffer("file; filename="); } //如果系统是运行在中文平台下,则将文件名转码为ISO8859_1的编码 disName = new String(disName.getBytes("GBK"), "ISO8859_1"); header.append(disName); response.setHeader("Content-Disposition", header.toString()); byte[] buffer = new byte[1024 * 512]; while (true) { int bytes = fileIn.read(buffer); if (bytes == -1) { break; } response.getOutputStream().write(buffer, 0, bytes); } response.getOutputStream().flush(); response.getOutputStream().close(); fileIn.close(); } catch (Exception e) { e.printStackTrace(); }