1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public class DownloadFileServlet extends HttpServlet {
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
try {
InputStream is = new FileInputStream("c:/dd.txt");
OutputStream os = arg1.getOutputStream();
arg1.setContentType("text/plain");
arg1.setHeader("Content-
Disposition","attachment;filename=toto.txt");
int count;
byte buf[] = new byte[4096];
while ((count = is.read(buf)) > -1)
os.write(buf, 0, count);
is.close();
os.close();
} catch (Exception e) {
// Y a un problème.
}
}
} |
Partager