Here you can find the source of moveFile(String pathBefore, String pathAfter)
public static void moveFile(String pathBefore, String pathAfter) throws java.io.FileNotFoundException, java.io.IOException
//package com.java2s; /*//from w w w .j a v a 2 s. c o m * PortUtil.cs * Copyright ? 2009-2011 kbinani * * This file is part of org.kbinani. * * org.kbinani is free software; you can redistribute it and/or * modify it under the terms of the BSD License. * * org.kbinani is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { public static void moveFile(String pathBefore, String pathAfter) throws java.io.FileNotFoundException, java.io.IOException { copyFile(pathBefore, pathAfter); deleteFile(pathBefore); } public static void copyFile(String file1, String file2) throws FileNotFoundException, IOException { FileChannel sourceChannel = new FileInputStream(new File(file1)).getChannel(); FileChannel destinationChannel = new FileOutputStream(new File(file2)).getChannel(); sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel); sourceChannel.close(); destinationChannel.close(); } public static void deleteFile(String path) { new File(path).delete(); } }