将文件写入ServletOutputStream的最有效方法 [英] Most effective way to write File to ServletOutputStream

查看:1352
本文介绍了将文件写入ServletOutputStream的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

将文件写入javax.servlet.ServletOutputStream的最有效方法是什么?

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

编辑:

如果使用NIO,这不会更有效吗?

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

推荐答案

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

中的 FileInputStream out SocketOutputStream
IOUtils 是来自 Apache Commons 中的http://commons.apache.org/io/\">Commons IO 模块。

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

这篇关于将文件写入ServletOutputStream的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆