i'm trying to create a page where users can download some .log file. this is the code :
if(action.equalsIgnoreCase("download")){
String file = (String)request.getParameter("file");
response.setHeader("Content-Disposition",
"attachment;filename="+file+"");
response.setContentType("text/plain");
File down_file = new File("log/"+file);
FileInputStream fileIn = new FileInputStream(down_file);
ServletOutputStream out = response.getOutputStream();
byte[] outputByte = new byte[4096];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 4096) != -1)
{
out.write(outputByte, 0, 4096);
}
fileIn.close();
out.flush();
out.close();
return null;
}
where am i doing wrong ? when i click on the download button it correctly ask me to save the file, but it is always a 0 byte file...
down_file.canRead()
return true? – Xaerxess Aug 1 '12 at 16:01