Here you can find the source of moveFiles(File src, String newSrc, File dest)
Parameter | Description |
---|---|
src | The source |
newSrc | The new source |
dest | The destination |
public static boolean moveFiles(File src, String newSrc, File dest)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.*; public class Main { /**//from ww w . ja va 2 s. c o m * Moves the source file to the destination file (similar to {@link #copyFiles(File, File)} but with deletion)<br> * * @param src The source * @param newSrc The new source * @param dest The destination * @return The result */ public static boolean moveFiles(File src, String newSrc, File dest) { boolean r = false; if (!dest.exists()) { r = dest.mkdirs(); } File[] files = src.listFiles(); if (files == null) { try { Files.move(src.toPath(), new File(dest, newSrc).toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace(); } return false; } for (File srcFiles : files) { if (srcFiles.isDirectory()) { r = moveFiles(srcFiles, newSrc, new File(dest, srcFiles.getName())); continue; } try { Files.move(srcFiles.toPath(), new File(dest, srcFiles.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace(); } } return r; } }