Problema para abrir o arquivos office depois de fazer o download via java[RESOLVIDO]

1 resposta
M

Pessoal,

Quando faço o download do arquivo .xlsx do excel, ou .docx ou pptx apararece a seguinte mensagem.

“O Excel encontrou conteúdo ilegível no arquivo ‘xxxx.xlsx’. Deseja recuperar o conteúdo?”

O que fazer para quando fazer o download do arquivo não abrir esta mensagem?

Estou fazendo assim para abrir.

String file = request.getParameter("f");
	File f = new File(file);
	String filename = f.getName();
	response.setContentType("application/text");
	response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

	String name = f.getName().substring(f.getName().lastIndexOf("/") + 1, f.getName().length());
	InputStream in = new FileInputStream(f);
	ServletOutputStream outs = response.getOutputStream();

	int bit = 256;
	int i = 0;
	try {
		while ((bit) >= 0) {
			bit = in.read();
			outs.write(bit);
		}
	} catch (IOException ioe) {
		ioe.printStackTrace(System.out);
	}
	outs.flush();
	outs.close();
	in.close();

Desde já agradeço a ajuda

Marcos

1 Resposta

M

O problema era com os mime types.

Criado 17 de fevereiro de 2012
Ultima resposta 19 de fev. de 2012
Respostas 1
Participantes 1