import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.*;public class DownloadChannel
{
    protected String filenameEncoding = "GBK";
    /**
     *
     */
    public DownloadChannel()
    {
    }    /**
     *
     * @param showName
     * @param fileName
     * @param response
     * @return
     */
    public boolean display(String showName, String fileName,
   HttpServletResponse response)
    {
FileInputStream in = null;
OutputStream out = null; try
{
    if (fileName == null)
return false;
    if (showName == null)
showName = fileName.substring(fileName.lastIndexOf(File.
    separator) + 1, fileName.length());     showName = new String(showName.getBytes(filenameEncoding),
  "iso-8859-1");
    response.setContentType("application/octet-stream");
    response.addHeader("Content-Disposition",
       "attachment; filename=" + showName);
    long fileSize = new File(fileName).length();
    response.setContentLength( (int) fileSize);
    in = new FileInputStream(fileName);
    out = response.getOutputStream();
    byte[] buffer = new byte[4096];
    int len = -1;
    while ( (len = in.read(buffer)) != -1)
    {
out.write(buffer, 0, len);
    }     response.flushBuffer(); } catch (Exception ex)
{
    return false;
} finally
{
    if (in != null)
    {
try
{
    in.close();
} catch (Exception e)
{
}
    }
    if (out != null)
    {
try
{
    out.close();
} catch (Exception e)
{
}
    }
    return true;
}
    }
    }
在servlet里调用