問題:在ftp創建文件夾時只能單目錄創建,比如"/user";不能一次創建多個"/user/zx",不能滿足功能需求
解決方案
1 /** 2 * 驗證是否存在文件夾 不存在 創建 ISO防止中文亂碼 3 * @param ftpClient 4 * @param ndir 基本路徑 5 * @param idir 校驗路徑 6 * @throws Exception 7 */ 8 public static void checkDirLoop(FTPClient ftpClient, String ndir ,String idir) 9 throws Exception { 10 try { 11 boolean flag = false;//不存在 12 String[] dirs = idir.split("\\/"); 13 String path =""; 14 String charest = ftpClient.getControlEncoding(); 15 for(String name : dirs){ 16 if(Tools.processNull(name).equals("")) 17 continue; 18 FTPFile[] ftpFileArr = ftpClient.listFiles(new String((ndir+path).getBytes(),charest)); 19 path+="/"+name; 20 for (FTPFile ftpFile : ftpFileArr) {//遍歷dir是否存在subDir 21 if(ftpFile.isDirectory() && ftpFile.getName().equalsIgnoreCase(new String(name.getBytes(),charest))){ 22 flag=true; 23 } 24 } 25 if (!flag) { 26 if (!ftpClient.makeDirectory(new String((ndir+path+"/").getBytes(),charest))) { 27 throw new Exception(ndir+path + "目錄創建失敗!"); 28 } 29 } 30 } 31 } catch (Exception e) { 32 throw new Exception(ndir + idir + "創建失敗!"); 33 } 34 }