RemoteIterator<LocatedFileStatus> files = fs.listFiles(<path-to-dir>, true)
// from iterator, determine if dir is empty
FileStatus[] files = fs.listStatus(<path-to-dir>)
// use array length to determine if dir is empty
// This also throws FileNotFoundException if file/dir does not exist, you can use it to determine if dir/file does not exist
检查文件是否为空。参见api文档this和this
long length = fs.getFileStatus(<file-path>).getLen()
// based on length determine if file is empty
1条答案
按热度按时间z9ju0rcb1#
作为方法的附件,您可以按以下方式执行:
检查dir是否为空。见api文件
检查文件是否为空。参见api文档this和this