ファイルをコピーするする方法

・ファイルを扱うユーティリティクラス


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileUtil {
    /**
     * ファイルのコピーを行う
     * @param from コピー元の File オブジェクト
     * @param to コピー先の File オブジェクト
     * @return コピーが正常に行われた場合は true、そうでない場合は false
     */
    public static boolean copy(File from, File to) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            long length = from.length();
            byte[] byteData = new byte[(int)length];
            fis = new FileInputStream(from);
            fis.read(byteData);
            fos = new FileOutputStream(to);
            fos.write(byteData);
        } catch(Exception e) {
            return false;
        } finally {
            if(fis != null) {
                try {
                    fis.close();
                } catch(Exception e) {
                    return false;
                }
            }
            if(fos != null) {
                try {
                    fos.flush();
                    fos.close();
                } catch(Exception e) {
                    return false;
                }
            }
        }
        return true;
    }
}