如何检测ftp文件名是一个目录? [英] How to detect ftp file name is a directory?

查看:173
本文介绍了如何检测ftp文件名是一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

p>我将使用 apache FTP客户端为此。在该库中有一个方法叫做 listFiles(),返回一个 FTPFile 。对于每个 FTPFile ,可以调用 getType()方法来确定类型代码常量为目录或文件。从getType()的java文档引用: -

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.

希望这有帮助!

这篇关于如何检测ftp文件名是一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆