Search code examples
javaioiostreamniochannel

coping streams - nio's channels vs. 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?


Solution

  • 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.