0
我试图检查文件是否存在于FTP中。当用一个用户测试时,它似乎很好。但是对于多个用户的情况,它似乎会抛出以下异常: 线程“main”中的异常sun.net.ftp.FtpProtocolException:欢迎信息:421.通过ftp连接来确定文件是否存在
下面是我们用来检查文件在那里,我们已经关闭所有的连接,但它仍然抛出sun.net.ftp.FtpProtocolException:欢迎留言:421
public boolean getFtpFileExists(String fileUrl)
{
URL theURL = null;
InputStream inputStream = null;
FtpURLConnection ftpUrlConn = null;
boolean ftpFileExists = false;
try
{
theURL = new URL(fileUrl);
ftpUrlConn = (FtpURLConnection)theURL.openConnection();
inputStream = ftpUrlConn.getInputStream();//calling this method will throw a 'FileNotFoundException' if doesn't exist
ftpFileExists = true;
}
catch(FileNotFoundException fnfe)
{
ftpFileExists = false;
}
catch(Exception e)
{
System.out.println(e.toString());
ftpFileExists = false;//hmm, not sure really!
}
finally
{
//close inputStream & connection
if(inputStream != null)
{
try
{
inputStream.close();
}
catch(IOException ioe)
{
System.out.println("Error closing input stream: "+ioe.getMessage());
}
}
try
{
ftpUrlConn.close();
}
catch(Exception e)
{
System.out.println("Error closing ftpUrlConnection");
}
}
return ftpFileExists;
}
任何人都可以帮助我吗?
可能的重复[检查是否存在使用java的“ftp”url](http://stackoverflow.com/questions/18316468/check-if-file-with-ftp-url-exists-using-java) – user2504380 2014-10-06 09:54:16