0

I am retrieving a list of files from a particular location on an FTP server and then i need to check if a particular filename is in it. if the file dosent exist, i want to provide an alternate filename to check.

FTPFile[] ftpFiles = ftp.listFiles(pdfBean.getFileLocation());
String fileName = pdfBean.getFileName().tostring();

How can i check if filename exists in ftpFiles?

4

2 回答 2

1

只需循环运行ftpFiles

String fileName = pdfBean.getFileName().tostring();   

private boolean isFtpFileExist(String fileName){
for(FTPFile file : ftpFiles ){

       if (file.getType() == FTPFile.FILE_TYPE) {
            // ....
          if(file.getName().equals(fileName)){
             return true;
          }
        }

    }

 return false;
 }
于 2013-10-24T16:58:25.977 回答
0

你可以做类似的事情

FTPFile primary;
FTPFile secondary;
String pFileName; // primary file
String sFileName; // secondary file name
// set those name strings...
for(int i = 0; i < ftpFiles.length; ++i) {
   if(ftpFiles[i].getName() == pFileName)
      primary = ftpFiles[i];
   else if(ftpFiles[i].getName() == sFileName)
      secondary = ftpFiles[i];
}

由于您有一个标准数组,因此您需要自己搜索它。

于 2013-10-24T17:03:46.880 回答