Java Reference
In-Depth Information
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class MoveAndCopyFiles {
public static void main(String[] args) {
Path current = Paths.get("D:/Beginning Java SE 7/Projects/
MoveAndCopyFiles");
Path newDir = Paths.get("junkDir");
// New directory for files
newDir = newDir.toAbsolutePath();
// Make path absolute
createSingleDirectory(newDir);
// Create directory in
current
// Copy files from current directory to new
System.out.println("Copying files from " + current + " to " +
newDir);
if(!copyFiles(current, newDir)) {
System.out.println("Copying files failed.");
return;
}
System.out.println(
"You can look at the directory to verify that the copy has
worked.");
System.out.println("Press Enter to continue.");
waitForEnter();
// Create another subdirectory in current
Path newDir2 = Paths.get("junkDirBackup");
newDir2 = newDir2.toAbsolutePath();
// Make path absolute
createSingleDirectory(newDir2);
// Create directory in
current
// Move files from newDir to newDir2
System.out.println("Moving files from " + newDir + " to " +
newDir2);
if(!moveFiles(newDir, newDir2)) {
System.out.println("Moving files failed.");
return;
}
System.out.println(
"You can look at the directory to verify that the move has
worked.");
System.out.println("Press Enter to continue.");
waitForEnter();
// Now we can delete newDir because it is empty
Search WWH ::




Custom Search