摘记: 本文为大家分享了java判断ftp目录是否存在的方法,供大家参考,具体内容如下 ```java package com.soft4j.log4j; import java.io.IOException; import sun.net.ftp.FtpClient; public class FtpTest { static String ..

本文为大家分享了java判断ftp目录是否存在的方法,供大家参考,具体内容如下

package com.soft4j.log4j;
import java.io.IOException; 
import sun.net.ftp.FtpClient;
 
public class FtpTest
{
 static String middle_ftpServer = "10.103.2.250";
 static String middle_user = "ora9iftp";
 static String middle_password = "ftp";
 static String middle_dir = "/image/NWKPHOTO/Middle/2009/3";
 
 public static void main(String[] args)
 {
 FtpClient ftpClient = new FtpClient();
 try
 {
 ftpClient.openServer(middle_ftpServer);
 ftpClient.login(middle_user, middle_password);
 FtpTest ft = new FtpTest();
 ft.isDirExist(ftpClient, middle_dir);
 } catch (IOException e)
 {
 e.printStackTrace();
 }
 
 }
 
 /** 判断Ftp目录是否存在 */
 public boolean isDirExist(FtpClient ftpClient, String dir)
 {
 try
 {
 ftpClient.cd(dir); 
 } catch (IOException e1)
 {
  reurn false;
 }
 return true;
 }
}