I've never done this, so I can't vouch for the efficiency or correctness of this. Also, I'm not really used to working with Streams, so that's another thing you'll have to test and work out.
Code:
FileInputStream fis = new FileInputStream(<file location>);
int fileLength = fis.available();
byte[] bytes = new byte[fileLength];
fis.read(bytes);
response.setContentType(<XLS content flag>);
response.getOutputStream().write(bytes);
response.getOutputStream().flush();
response.getOutputStream().close();
fis.close();
Alternately, you could do it this way:
Code:
FileInputStream fis = new FileInputStream(<file location>);
int fileLength = fis.available();
response.setContentType(<XLS content flag>);
for(int i =0; i < fileLength; i++){
byte current = fis.read();
response.getOutputStream().write(current);
}
response.getOutputStream().flush();
response.getOutputStream().close();
fis.close();
That may or may not be more efficient/use a smaller footprint. You'll have to experiment to find out.