是否可以通过文件名删除文件,而不需要扩展名。我正在使用FTPClient连接到我的FTP服务器,工作非常出色。我只能上传3种格式的文件(.png,.jpg,.gif)。事实上,只有当我指定这样的扩展名并工作时,我才能删除文件:
ftp.deleteFile("/"+productID+setFileName+".png");但是我想删除文件,不管文件的扩展名是什么,只有文件名。谢谢
发布于 2017-03-17 16:13:59
startsWith()函数怎么样?
org.apache.commons.net.ftp.FTPClient ftpClient=new FTPClient(); //instantiate the FTPClient
FTPFile[] ftpFiles=ftpClient.listFiles();//get the list of files in the root directory of the FTP server
for(FTPFile tempFtpFile:ftpFiles)
{
//go through the list of files and delete those that start with your required prefix
String tempFtpFileName=tempFtpFile.getName();
if(tempFtpFileName.startsWith(productID+setFileName))
ftpClient.deleteFile(tempFtpFile.getName());
}发布于 2017-03-17 16:02:31
这取决于您的ftp客户端是否实现了ftp命令mdelete。
AFAIK mdelete接受通配符。或者您的服务器在执行删除命令时接受通配符。
如果你试图执行:
ftp.deleteFile("/"+productID+setFileName+".*");https://stackoverflow.com/questions/42862048
复制相似问题