response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename="xxx.txt");
InputStream is = new FileInputStream("要下載檔案的Path");
OutputStream os = response.getOutputStream();
int n = 0;
byte[] ba = new byte[1024];
while((n = is.read(ba)) != -1){
os.write(ba, 0, n);
}
is.close();
out.flush();
out.close();
response.setStatus(response.SC_OK);
response.flushBuffer();
沒有留言:
張貼留言