Did so. For now, see what happens with speed.
public class FileMove { private static boolean globalPause = false; /** * Снять/установить общую паузу * @param type true установить, false снять */ public static void setGlobalPause(boolean type) { globalPause = type; } /** * Перемещение файла * @param from откуда * @param to куда * @throws IOException ошибка копирования * @throws InterruptedException ошибка паузы */ public static void copy(File from, File to) throws IOException, InterruptedException { if(to.exists()) { to.delete(); } FileInputStream inFile = new FileInputStream(from); FileOutputStream outFile = new FileOutputStream(to); FileChannel inChannel = inFile.getChannel(); FileChannel outChannel = outFile.getChannel(); long bufferSize = 8 * 1024; long pos = 0; long count; long size = inChannel.size(); while (pos < size) { if(globalPause) { Thread.sleep(100); continue; } count = size - pos > bufferSize ? bufferSize : size - pos; pos += inChannel.transferTo(pos, count, outChannel); } inFile.close(); outFile.close(); } /** * Перемещение файла * @param from откуда * @param to куда * @throws IOException ошибка копирования * @throws InterruptedException ошибка паузы */ public static void move(File from, File to) throws IOException, InterruptedException { copy(from, to); from.delete(); } }
Files.move()method, it is in a piece of example code. And it works, apparently, through copying and deleting. - lampa