<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: NIO code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 06:20:17 GMT</pubDate>
    <description>DZone Snippets: NIO code</description>
    <item>
      <title>Java filecopy using NIO</title>
      <link>http://snippets.dzone.com/posts/show/4946</link>
      <description>&lt;code&gt;&lt;br /&gt;    public static void fileCopy( File in, File out )&lt;br /&gt;            throws IOException&lt;br /&gt;    {&lt;br /&gt;        FileChannel inChannel = new FileInputStream( in ).getChannel();&lt;br /&gt;        FileChannel outChannel = new FileOutputStream( out ).getChannel();&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;//          inChannel.transferTo(0, inChannel.size(), outChannel);      // original -- apparently has trouble copying large files on Windows&lt;br /&gt;&lt;br /&gt;            // magic number for Windows, 64Mb - 32Kb)&lt;br /&gt;            int maxCount = (64 * 1024 * 1024) - (32 * 1024);&lt;br /&gt;            long size = inChannel.size();&lt;br /&gt;            long position = 0;&lt;br /&gt;            while ( position &lt; size )&lt;br /&gt;            {&lt;br /&gt;               position += inChannel.transferTo( position, maxCount, outChannel );&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        finally&lt;br /&gt;        {&lt;br /&gt;            if ( inChannel != null )&lt;br /&gt;            {&lt;br /&gt;               inChannel.close();&lt;br /&gt;            }&lt;br /&gt;            if ( outChannel != null )&lt;br /&gt;            {&lt;br /&gt;                outChannel.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 04 Jan 2008 22:40:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4946</guid>
      <author>frost137 (Douglas Wyatt)</author>
    </item>
  </channel>
</rss>
