Useful if org.apache.commons.io.FileUtils not available.

This commit is contained in:
Christian P. MOMON 2010-08-13 10:34:13 +02:00
parent b36e4dfb8d
commit f432dc1e2c

View file

@ -0,0 +1,59 @@
package fr.devinsy.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* Never used. Prefer org.apache.commons.io.FileUtils class.
*/
public class FileCopier
{
static final public int BUFFER_SIZE = 4*1024;
/**
*
*/
static void copy (File source, File target) throws Exception
{
if ((source == null) || (target == null))
{
throw new Exception("Null parameter.");
}
else
{
FileInputStream in = new FileInputStream(source);
FileOutputStream out = new FileOutputStream(target);
try
{
byte[] buffer = new byte[BUFFER_SIZE];
boolean ended = false;
while (!ended)
{
int size = in.read(buffer);
if (size == -1)
{
ended = false;
}
else
{
out.write(buffer, 0, size);
}
}
}
finally
{
if (in != null)
{
in.close();
}
if (out != null)
{
out.close();
}
}
}
}
}