简体   繁体   English

下载多种文件类型

[英]download multiple files types

I am using jsp servlet to upload and download files. 我正在使用jsp servlet上载和下载文件。

I want to download many types of files, so I choose to download them as zip files in order not to fall in defining each type of attachment in the response, when I make upload all of files uploaded correctly, when I make download for txt and docx files they are downloaded correctly too, but when I download pdf or image files, they are not downloaded correctly, since I put them in the same folder! 我想下载许多类型的文件,所以我选择将它们下载为zip文件,以便当我正确上传所有文件,为txt下载和docx文件也可以正确下载,但是当我下载pdf或图像文件时,它们却没有正确下载,因为我将它们放在了同一文件夹中!

when I make download for txt and docx files they are downloaded correctly too, but when I download pdf or image files, they are not downloaded correctly 当我为txt和docx文件进行下载时,它们也都正确下载,但是当我下载pdf或图像文件时,它们没有正确下载

Fact: .txt and .docx (XML!) files are text based while PDF and images are binary based. 事实: .txt.docx (XML!)文件是基于文本的,而PDF和图像是基于二进制的。

So, it sounds much like that you read/write files using Reader / Writer instead of InputStream / OutputStream . 因此,听起来很像是使用Reader / Writer而不是InputStream / OutputStream读/写文件。

Fix the code accordingly. 相应地修改代码。 Never use Reader / Writer as long as you're not interested in the actual file content on a character basis. 只要您对基于字符的实际文件内容不感兴趣,就不要使用Reader / Writer It will totally corrupt binary files. 它将完全破坏二进制文件。 You can find a basic example of a download servlet here . 您可以在此处找到下载servlet的基本示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM