In Java I'm trying to delete a ftp directory. But if it's not empty, I need to delete all files and sub-dirs in it, by calling files[]=ftp.dir()
. I can get a list from the dir, but how can I tell if one of the items in the list is a file or sub-dir ? Is there a files[i].IsDirectory
method in ftp command?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I would use apache FTP Client for this. In that library there is a method called listFiles() that returns an array of FTPFile. For each FTPFile
you can call the getType() method to determine the type code constant for a directory or a file. Quote from the java docs of getType():-
public int getType()
Return the type of the file (one of the _TYPE constants), e.g., if it is a directory, a regular file, or a symbolic link.
Returns:
The type of the file.
Hope this helps!
回答2:
Take a look of this : http://www.example-code.com/java/ftp_deleteTree.asp