Hello all y'all,

i want to write a servlet that enables the user to download a file; i'm
using the following code to do this but i get an IllegalStateException while
executing it. Any ideas what might be wrong?

The code fragment:

public void service(..) ... {

    String filename = request.getParameter("file");
    FileInputStream fis = new FileInputStream(filename);
     BufferedInputStream bis = new BufferedInputStream(fis);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     int ch;
     while ((ch = bis.read()) != -1) {
      baos.write(ch);
     }
     byte buffer[] = baos.toByteArray();
     response.setContentType("application/octet-stream");
     response.setHeader("Content-Disposition", "attachment;filename=" +
filename);
    ServletOutputStream out = response.getOutputStream();
     out.write(buffer);
}

Thanks in advance for your ideas.

Michael Weller

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to