사용자가 .log 파일을 다운로드 할 수있는 페이지를 만들려고합니다. 이 코드는 다음과 같습니다.봄에서 모델 및 뷰에서 파일 다운로드
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;
}
어디에서 잘못 했습니까?
IOUtils.copy(fileIn, response.getOutputStream());
response.flushBuffer();
아파치 커먼즈 IO를 여기에서 찾을 수 있습니다 내가 다운로드 버튼을 클릭하면 로 시도 ...
'down_file.canRead()'가 true를 반환합니까? – Xaerxess
예, true를 반환합니다. – Medioman92