Here you can find the source of moveFile(String source, String target)
public static void moveFile(String source, String target) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.*; import java.nio.channels.FileChannel; public class Main { public static void moveFile(String source, String target) throws Exception { copyFile(source, target);/*from w w w .ja v a2s . c o m*/ deleteFile(source); } public static void copyFile(String source, String target) throws Exception { copyFile(new File(source), new File(target)); } /** * fast file copy * * @param source source file * @param target target file * @throws Exception if error occurs */ public static void copyFile(File source, File target) throws Exception { FileInputStream fis = new FileInputStream(source); FileOutputStream fos = new FileOutputStream(target); FileChannel inChannel = fis.getChannel(); FileChannel outChannel = fos.getChannel(); // inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparently has trouble copying large files on Windows // magic number for Windows, 64Mb - 32Kb int maxCount = (64 * 1024 * 1024) - (32 * 1024); long size = inChannel.size(); long position = 0; while (position < size) { position += inChannel.transferTo(position, maxCount, outChannel); } inChannel.close(); outChannel.close(); fis.close(); fos.close(); } public static void deleteFile(String source) throws Exception { new File(source).delete(); } }