IAdapter IAdapter - 1 year ago 86
Java Question

Most effective way to write File to ServletOutputStream

ServletOutputStream output = response.getOutputStream();

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


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

Answer Source
IOUtils.copy(in, out);
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.