Hadoop删除目录的方法可以通过以下两种方式:
hadoop fs -rm -r /path/to/test
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class DeleteDirectory {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path directory = new Path("/path/to/test");
if (fs.exists(directory)) {
fs.delete(directory, true);
System.out.println("Directory deleted successfully");
} else {
System.out.println("Directory doesn't exist");
}
fs.close();
}
}
以上是两种常用的方法来删除Hadoop中的目录。您可以根据自己的需求选择其中一种来删除目录。