是否可以按文件名删除不带扩展名的文件。我正在使用 FTPClient 连接到我的 FTP 服务器并且工作得很好。我只能上传 3 种格式的文件(.png、.jpg、.gif)。事实上,只有当我指定这样的扩展名并且工作时,我才能删除该文件:
ftp.deleteFile("/"+productID+setFileName+".png");
但我想删除该文件,无论文件的扩展名是什么,只按文件名。谢谢
最佳答案
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());
}
关于java - 使用Java在FTP上按文件名删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42862048/