private void moveTotherFolders(String pathName,String fileName,String ansPath){ String startPath = this.path + pathName + File.separator + fileName; String endPath = ansPath + File.separator + currentDate + File.separator; try { File startFile = new File(startPath); File tmpFile = new File(endPath);//獲取文件夾路徑 if(!tmpFile.exists()){//判斷文件夾是否創建,沒有創建則創建新文件夾 tmpFile.mkdirs(); } System.out.println(endPath + startFile.getName()); if (startFile.renameTo(new File(endPath + startFile.getName()))) { System.out.println("File is moved successful!"); log.info("文件移動成功!文件名:《{}》 目標路徑:{}",fileName,endPath); } else { System.out.println("File is failed to move!"); log.info("文件移動失敗!文件名:《{}》 起始路徑:{}",fileName,startPath); } } catch (Exception e) { log.info("文件移動異常!文件名:《{}》 起始路徑:{}",fileName,startPath); } }
這個方法的作用就是,將startPath 下的文件 fileName 移動到endPath 下
