Galera,
 
depois de muitas batalhas nasceu a crianca....
 
Abaixo esta o codigo que faz download de arquivo zip (fora do WebServer) para o cliente (servidor->cliente):
 
OutputStream out = null;
// nome do arquivo que aparecera para o cliente salvar
response.setHeader( "Content-Disposition", "attachment; filename = Arquivo.zip" );
out = new ZipOutputStream( response.getOutputStream() );
// insira os seus arquivos que farao parte do Arquivo.zip
( ( ZipOutputStream ) out ).putNextEntry( new ZipEntry( "Direcao.htm" ) );
response.setContentType( "application/x-compress" );
 
// substitua o codigo abaixo caso vc queira passar um arquivo executavel
// response.setHeader( "Content-Disposition", "attachment; filename = Arquivo.exe" );
// out = response.getOutputStream();
// response.setContentType( "octet-stream" );
 
// se for arquivo executavel troque o nome: Arquivo.exe
String sFile = "c:/Arquivo.zip"; // este arquivo contem Direcao.htm compactado
 
// Return the file
try {
  FileInputStream fis = null;
  try {
    fis = new FileInputStream( file );
    byte[] buf = new byte[ 4 * 1024 ];  // 4K buffer
    int bytesRead;
    while( ( bytesRead = fis.read( buf ) ) != -1 ) {
      out.write( buf, 0, bytesRead );
    }
  }
  finally {
    if (fis != null) fis.close();
  }
}
catch( Exception e ) {
  System.out.println( e.toString() );
}
out.close();
 
Para quem nao entendeu o que eu queria, deixo a mensagem em Ingles tbem a qual consegui obter algumas dicas la fora:
 
Normally when user clicks on a link of a static file, browser will try to get
this file and run it/save it to disk.  How can I do the similar thing if the file
is generated by servlet and it's loaded
from an internal network disk (outside the web server's path)???
 
Qualquer duvida e-mail-me...
 
Obrigado a todos que me responderam...
 
Alessandro.
 
 
-----Original Message-----
From: Alessandro Boeira dos Reis <[EMAIL PROTECTED]>
To: Java Terra <[EMAIL PROTECTED]>
Date: Quinta-feira, 4 de Fevereiro de 1999 10:02
Subject: Download a partir Servlet

Ola pessoal,
 
alguem sabe como fazer um download de um arquivo local (fora do servidor de web) a partir de uma Servlet???
 
Desde ja grato,
Alessandro.

Responder a