Sunday, October 10, 2004 05:21 PM
You should be treating files as byte streams, not character streams. The problem is is that you open a stream of bytes and with a FileReader. When you use a FileReader, you are assuming that the bytes represent characters and Java does the byte to character translation for you. That is why it works for text files, but not for other files.
What you really want to do is this:
response.setHeader("Content-Disposition", "attachment; filename="" + file.getName() + """);
OutputStream out = response.getOutputStream()
InputStream in = new FileInputStream(file.getName());
byte buffer = new byte;
Don't use Reader, don't use Writers, don't use Strings, don't use StringBuffers. All of those assume that the file contains character data.
Do use InputStreams, OutputStreams, and byte arrays.