2011-02-13 55 views
2

在Java中,我試圖刪除一個ftp目錄。但是如果它不是空的,我需要通過調用files[]=ftp.dir()來刪除它中的所有文件和子目錄。我可以從目錄中獲取一個列表,但是如何判斷列表中的某個項目是文件還是子目錄?在ftp命令中是否有files[i].IsDirectory方法?如何檢測ftp文件名是一個目錄?

回答

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. 

希望這有助於!

相關問題