String relative_path = ParameterParser.getStrPara(request, "path"); String filename = ParameterParser.getStrPara(request, "filename"); String mime = ParameterParser.getStrPara(request, "mime");
if (mime.length() > 0) { response.setContentType(mime); } else { response.setContentType("application/*"); } response.setHeader("Content-Disposition", "attachment;filename=" + filename);
InputStream in = download(relative_path);
if (in == null) { Log.debug("文件" + filename + "不存在.", this); response.getOutputStream().close(); return; } byte[] b = new byte[1024]; int len; while ( (len = in.read(b)) > 0) { response.getOutputStream().write(b, 0, len); } in.close(); response.getOutputStream().flush(); response.getOutputStream().close();
}
} |