<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bytearray - Programming, Computers and Technology &#187; java file copy</title>
	<atom:link href="http://bytearray.brixtonjunkies.com/tag/java-file-copy/feed/" rel="self" type="application/rss+xml" />
	<link>http://bytearray.brixtonjunkies.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Nov 2009 11:52:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Java: File Copy and File Move</title>
		<link>http://bytearray.brixtonjunkies.com/2009/10/07/java-file-copy-and-file-move/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/10/07/java-file-copy-and-file-move/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 14:12:06 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[java file copy]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=604</guid>
		<description><![CDATA[It has been a while since I&#8217;ve done any major Java development, it seems I have got used to having all the standard file tools which are available in scripted 4th and 5th generation languages like PHP. Java whilst incredibly powerful is sometimes a bit awkward when dealing with certain problems. Often it&#8217;s the level [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a while since I&#8217;ve done any major Java development, it seems I have got used to having all the standard file tools which are available in scripted 4th and 5th generation languages like PHP. </p>
<p>Java whilst incredibly powerful is sometimes a bit awkward when dealing with certain problems. Often it&#8217;s the level abstraction and/or ability to get under the hood that can cloud a somewhat simple task, in my case <strong>file copying and moving</strong>.</p>
<p>Here is a small package that simplifies file copies and moves <img src='http://bytearray.brixtonjunkies.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: java; title: ; notranslate">
package Utils.SystemTools;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileCopy{

	public static void copy(File source,File dest) throws IOException{
		try{
			copy(source.getPath(),dest.getPath());
		}
		catch (IOException e){
			throw e;
		}
	}

	public static void copy(String source,String dest) throws IOException{
		try{
			File sourceFile = new File(source);
			File destFile = new File(dest);
			InputStream in = new FileInputStream(sourceFile);
			OutputStream out = new FileOutputStream(destFile);

			int bufferSize = 1024;
			byte[] buf = new byte[bufferSize];
			int len;
			while ((len = in.read(buf)) &gt; 0){
				out.write(buf,0,len);
			}
			in.close();
			out.close();
	    }
	    catch(IOException e){
	    	throw e;
	    }
	}

	public static void move(String source,String dest) throws IOException{
		try{
			copy(source,dest);
		}
		catch(IOException e){
			throw e;
		}
		File sourceFile = new File(source);
		if (!sourceFile.delete()){
			throw new IOException(&quot;File deletion failed for: &quot; + source);
		}
	}

	public static void move(File source,File dest) throws IOException{
		try{
			move(source.getPath(),dest.getPath());
		}
		catch(IOException e){
			throw e;
		}
		if (!source.delete()){
			throw new IOException(&quot;File deletion failed for: &quot; + source.getPath());
		}
	}	

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/10/07/java-file-copy-and-file-move/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

