document.write('<div class="java5" style="font-family: monospace;"><br />');
document.write('&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />');
document.write('&nbsp; &nbsp; &nbsp;* Copy a file to a new location<br />');
document.write('&nbsp; &nbsp; &nbsp;* @param _srcFilename The original file<br />');
document.write('&nbsp; &nbsp; &nbsp;* @param _destFilename The location where a copy should be created<br />');
document.write('&nbsp; &nbsp; &nbsp;* @param _tmpFile If true, the created file copy will be deleted on program exit<br />');
document.write('&nbsp; &nbsp; &nbsp;* @throws IOException If there are IO problems during the copy<br />');
document.write('&nbsp; &nbsp; &nbsp;*/</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> copyFile<span style="color: #66cc66;">&#40;</span><a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="color: #aaaadd; font-weight: bold;">String</span></a> _srcFilename, <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="color: #aaaadd; font-weight: bold;">String</span></a> _destFilename, <span style="color: #993333;">boolean</span> _tmpFile<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/IOException.html"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> <span style="color: #66cc66;">&#123;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create channel on the source</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/FileChannel.html"><span style="color: #aaaadd; font-weight: bold;">FileChannel</span></a> srcChannel = <span style="color: #000000; font-weight: bold;">new</span> <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileInputStream.html"><span style="color: #aaaadd; font-weight: bold;">FileInputStream</span></a><span style="color: #66cc66;">&#40;</span>_srcFilename<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getChannel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create destination file and associated directories if required</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"><span style="color: #aaaadd; font-weight: bold;">File</span></a> destFile = <span style="color: #000000; font-weight: bold;">new</span> <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span>_destFilename<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_tmpFile<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destFile.<span style="color: #006600;">deleteOnExit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"><span style="color: #aaaadd; font-weight: bold;">File</span></a> destDir = destFile.<span style="color: #006600;">getParentFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>destDir != <span style="color: #b13366;">null</span> &amp;&amp; !destDir.<span style="color: #006600;">exists</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destDir.<span style="color: #006600;">mkdirs</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_tmpFile<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destDir.<span style="color: #006600;">deleteOnExit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; destFile.<span style="color: #006600;">createNewFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create channel on the destination</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/FileChannel.html"><span style="color: #aaaadd; font-weight: bold;">FileChannel</span></a> dstChannel = <span style="color: #000000; font-weight: bold;">new</span> <a target="_blank"&nbsp; href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileOutputStream.html"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a><span style="color: #66cc66;">&#40;</span>_destFilename<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getChannel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Copy entirefile contents from source to destination</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; dstChannel.<span style="color: #006600;">transferFrom</span><span style="color: #66cc66;">&#40;</span>srcChannel, <span style="color: #cc66cc;">0</span>, srcChannel.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Close the channels</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; srcChannel.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; dstChannel.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/167/1/" target="_blank">byteMyCode</a>.</div>');
