Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
hadoop shell 有命令hadoop fs -rm /dir/*。但我没有从 API 中找到类似的。
hadoop fs -rm /dir/*
要删除目录中的文件而不删除目录本身或从任何子目录中删除文件(即做什么hadoop fs -rm /dir/*),您可以使用:
FileSystem fs = dir.getFileSystem(getConf()); RemoteIterator<LocatedFileStatus> it = fs.listFiles(dir, false); while (it.hasNext()) { fs.delete(it.next().getPath(), false); }