General J2EE: how to delete file?
i use "sun.net.ftp" package to read and save files hosted in a ftp server,now,i can "get" and "put" files to ftp server,but i can't find the "delete" method in the "FtpClient" client,if after i read a file,i want to delete it,how can i do?
After you "get" the file from ftp server, you should know where the file is located on your file system. Hence, you can create a java.io.File object and use the delete() method to delete the file. This method would return a boolean to indicate if the file deletion was successfully or not.
no,you misunderstand me,i want to delete the file from ftp server.
Since java.io.File class has a constructor which takes URI as the parameter, you can create an instance with something like "ftp://ftp.example.com/uri" and then use the same old delete() method afterwards.
FTPClient ftp = new FTPClient(); ftp.connect(ftpHost); ftp.login( ftpUser, ftpPWD ); //Returns true on successful login ftp.deleteFile(filePath); //Returns true on successful delete