FileInputStream bis = null;
ServletOutputStream bos = null;
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
// Устанавливаем тип содержимого
response.setContentType("application/"+str);
response.setHeader("Content-disposition","filename=file."+str);
try {
File fileName = new File("rep\\testReport."+str);
bis = new FileInputStream(fileName.getAbsolutePath());
bos = response.getOutputStream();
byte[] buff = new byte[2048];
int bytesRead;
while (-1 !=(bytesRead = bis.read(buff,0,buff.length)))
{
bos.write(buff,0,bytesRead);
}
response.getOutputStream().flush();
response.getOutputStream().close();
context.responseComplete();
}
catch (IOException e) {
e.printStackTrace();
}
} catch (JRException e) {
// TODO
}