Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most effective way to write File to ServletOutputStream

ServletOutputStream output = response.getOutputStream();
output.write(byte[]);

What is the most effective way to write File to javax.servlet.ServletOutputStream?

EDIT:

won't this be more effective if the NIO was used?

like image 614
IAdapter Avatar asked Jan 10 '11 09:01

IAdapter


1 Answers

IOUtils.copy(in, out);
out.flush();
//...........
out.close(); // depends on your application

Where in is the FileInputStream and out is the SocketOutputStream. IOUtils is a utility from Commons IO module in Apache Commons.

like image 178
AlexR Avatar answered Sep 21 '22 13:09

AlexR