ファイルコピーのJava1.5以降対応版。
FileUtil.java
/**
* NIOチャネルを使って高速にコピーします。
* @param srcPath コピー元パス
* @param dstPath コピー先パス
* @throws IOException IOエラー
*/
public static void copy(final String srcPath, final String dstPath) throws IOException {
FileChannel srcChannel = new FileInputStream(srcPath).getChannel();
FileChannel destChannel = new FileOutputStream(dstPath).getChannel();
try {
srcChannel.transferTo(0, srcChannel.size(), destChannel);
} finally {
srcChannel.close();
destChannel.close();
}
}
/**
* NIOチャネルを使って高速にコピーします。
* @param src コピー元パス
* @param dst コピー先パス
* @throws IOException IOエラー
*/
public static void copy(final File src, final File dst) throws IOException {
FileChannel srcChannel = new FileInputStream(src).getChannel();
FileChannel destChannel = new FileOutputStream(dst).getChannel();
try {
srcChannel.transferTo(0, srcChannel.size(), destChannel);
} finally {
srcChannel.close();
destChannel.close();
}
}