Hello
I use the scriplet shown below for downloading files.
When it's text file all is seems to be ok, but zip file is always corrupted.
I changed contentType ( response.setContentType("application/zip"); ) but it
didin't help.
What is wrong ? Can anybody help ?
Maciek
<%
String sourceFilePathName = myUserK.getStringParm ();
String destFileName = myUserK.getStringParm2 ();
java.io.File file = new java.io.File(sourceFilePathName);
FileInputStream fileIn = new FileInputStream(file);
long fileLen = file.length();
int readBytes = 0;
int totalRead = 0;
int blockSize = 65000;
byte b[] = new byte[blockSize];
String readData;
PrintWriter printWriter;
printWriter = response.getWriter();
response.setContentType("text/html; charset=ISO-8859-2");
response.setContentLength((int)fileLen);
response.setHeader("Content-Disposition", "attachment; filename=" +
destFileName);
while(totalRead < fileLen) {
readBytes = fileIn.read(b, 0, blockSize);
totalRead += readBytes;
readData = new String (b);
printWriter.write(readData, 0, readBytes);
}
printWriter.close ();
fileIn.close();
%>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets