download方法:
public String download(){
String path = "D:\\text";
String fileName = "1.jpg";
HttpServletResponse response = FacesUtil.getResponse();
String contentType = "application/x-download";
//设置下载标志头信息
response.setContentType(contentType);
StringBuffer contentDisposition = new StringBuffer();
contentDisposition.append("attachment;");
contentDisposition.append("filename=\"");
contentDisposition.append(fileName);
contentDisposition.append("\"");
response.setHeader("Content-Disposition", new String(contentDisposition.toString().getBytes()));
File file = new File(path,fileName);
try {
FileInputStream input = new FileInputStream(file);
ServletOutputStream output = response.getOutputStream();
byte[] bytes = new byte[1024*10];
int b = 1;
while (b > 0){
b = input.read(bytes,0,1024*10);
output.write(bytes,0,b);
}
input.close();
output.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}