【问题标题】:How to detect ftp file name is a directory?如何检测ftp文件名是目录?
【发布时间】:2011-02-13 18:43:59
【问题描述】:

在 Java 中,我试图删除一个 ftp 目录。但如果它不为空,我需要通过调用files[]=ftp.dir() 来删除其中的所有文件和子目录。我可以从目录中获取列表,但是如何判断列表中的一项是文件还是子目录? ftp 命令中有files[i].IsDirectory 方法吗?

【问题讨论】:

    标签: java ftp directory


    【解决方案1】:

    我会为此使用apache FTP Client。在那个库中有一个名为listFiles() 的方法,它返回一个FTPFile 的数组。对于每个FTPFile,您可以调用getType() 方法来确定目录或文件的type code constant。引用 getType() 的 java 文档:-

    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.
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2011-12-26
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 2015-07-15
      • 2017-08-16
      • 1970-01-01
      相关资源
      最近更新 更多