移动文件树
import static javax.swing.JOptionPane.ERROR_MESSAGE;/* 来自 n o w j a v a . c o m - 时 代 Java*/ import static javax.swing.JOptionPane.NO_OPTION; import static javax.swing.JOptionPane.QUESTION_MESSAGE; import static javax.swing.JOptionPane.YES_NO_OPTION; import static javax.swing.JOptionPane.showConfirmDialog; import static javax.swing.JOptionPane.showMessageDialog; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; public class Main{/* 来自 nowjava.com - 时代Java*/ public static String moveTree(File srcFile, File dstFolder) { try { String fname = srcFile.getName(); File moveTo = new File(dstFolder, fname); if (moveTo.exists()) { if (moveTo.isFile()) { if (showConfirmDialog(null, "Do you want to override file " + moveTo + "?", "Move", YES_NO_OPTION, QUESTION_MESSAGE) == NO_OPTION) { return ""; } Files.move(srcFile.toPath(), moveTo.toPath(), StandardCopyOption.REPLACE_EXISTING); } else { return String.format( "<html>Cannot move <b>%s</b> to <b>%s</b>.", projectRelative(srcFile.toPath()), projectRelative(dstFolder.toPath())); } } else { Files.move(srcFile.toPath(), moveTo.toPath(), StandardCopyOption.REPLACE_EXISTING); } }