Pedrosa 20 de mar. de 2009
Tente algo assim na sua Servlet:
response . setContentType ( "text/plain" );
response . setHeader ( "Content-disposition" , "attachment; filename=" + arquivo );
OutputStream out = response . getOutputStream ();
caiocb 20 de mar. de 2009
Pedrosa,
O código funcionou bem. Consegui fazer o downaload aqui na minha máquina, mas o arquivo baixado não contém informação alguma =\ Tentei incrementar o código com as linhas abaixo, mas também nao deu certo !
File file = new File ( fileOut );
FileWriter writer = new FileWriter ( file );
writer . write ( "temp.txt" );
writer . flush ();
writer . close ();
response . setContentType ( "text/plain" );
response . setHeader ( "Content-disposition" , "attachment; filename=" + fileOut );
OutputStream teste = response . getOutputStream ();
caiocb 20 de mar. de 2009
mais alguém pode me ajudar?
Pedrosa 20 de mar. de 2009
caiocb 23 de mar. de 2009
Pessoal,
Ainda não consegui. Utilizei as referencias dadas pelo colegas mais ainda nao tive êxito.
Fiz até 2 exemplos e gostaria que mostrarei aqui a fim de que entendam o que estou fazendo . . . .
O primeiro codigo apbre a página de download, mas salva o arquivo em branco…
FileInputStream stream = null ;
String path = "/opt/phylogenia/saidas/" ;
File file = new File ( path + fileOut + ".txt" );
int iRead ;
stream = new FileInputStream ( file );
while (( iRead = stream . read ()) != - 1 ){
out . write ( iRead );
}
out . flush ();
out . close ();
response . setContentType ( "inline/download" );
response . setHeader ( "Content-disposition" , "attachment; filename=" + fileOut + ".txt" );
Ja este segundo, exibe o conteudo do arquivo no browser
String txt = "/opt/phylogenia/saidas/" + fileOut + ".txt" ;
File file = new File ( txt );
FileOutputStream teste = new FileOutputStream ( fileOut );
teste . write ( txt . getBytes ());
teste . flush ();
teste . close ();
response . setContentType ( "text/plain" );
response . setHeader ( "Content-disposition" , "attachment; filename=" + fileOut + ".txt" );
ServletOutputStream os = response . getOutputStream ();
os . write ( txt . getBytes ());
os . flush ();
os . close ();
=\
caiocb 24 de mar. de 2009
Resolvido Galera…
Depois de quebrar muito a cabeça, consegui fazer oDownload do arquivo!
Tava fazendo besteira… tava chamando o arquivo no lugar errado =\ Fazer o que. É errando que se aprende
File file = new File ( "Caminho do arquivo " ) ;
int iRead ;
FileInputStream stream = new FileInputStream ( file ) ;
response .setContentType ( "text/plain" ) ;
response .setHeader ( "Content-disposition" ,"attachment; filename=nomedoarquivo.txt" ) ;
while (( iRead = stream .read ()) != - 1 ) {
out .write ( iRead ) ;
}
out .flush () ;
out .close () ;
Até mais !