应对流 - nio 的通道与 io
当你想将一个流复制到另一个流时,NIO 的通道比 IO 的输入流/输出流更快吗?如果没有,您什么时候会使用渠道?
Are NIO's Channels faster than IO's inputstreams/outputstreams when you want to copy one stream to another? if not when you would use channels?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于大多数用途来说这并不重要。如果您使用 NIO 直接缓冲区来复制数据,则可以节省一两个内存副本,并具有可测量的改进,但是我建议您执行您认为最简单的操作,并且在 Java 中它可能足够快。即您应该达到网络或磁盘子系统的限制。
我将从 IOUtils.copy(in, out); 开始看看这是否足够快。
For most uses it doesn't matter. If you use NIO direct buffers to copy the data is can save a memory copy or two and have a measurable improvement, however I suggest you do what you find simplest and it is likely to be more than fast enough in Java. i.e. you should reach the limits of your network or disk sub-system.
I would start with IOUtils.copy(in, out); and see if this is fast enough.