Boa tarde!
Estou com problemas para gerar esse Arquivo de Download…
String path = "c:\\Projetos\\download\\";
String filename = "B0010907.081";
String fullFileName = path + filename;
File file = new File(fullFileName);
byte[] buf = new byte[(int)file.length()];
try {
HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
String encodeUrl = response.encodeURL (fullFileName);
response.setContentType("application/text;");
response.addHeader("Content-Disposition","attachment;filename=\"" + filename + "\""+ encodeUrl);
response.setContentLength(buf.length);
OutputStream writer = response.getOutputStream();
writer.write(buf);
writer.flush();
writer.close();
System.out.println(response.getCharacterEncoding()) ;
FacesContext.getCurrentInstance().responseComplete();
} catch (Exception e) {
facesMessages.add("There is nothing to export with the selected dates");
}
}
Anteriormente realizei um Upload para fazer uma simulação de envio desse arquivo, onde esse arquivo é enviado e eu recebo, “trato” esse arquivo para finalmente deixar ele disponível para fazer o Download…
Só que quando esse download é realizado não aparece nada nesse arquivo mesmo ele tendo espaço.
