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中的目錄。您可以根據(jù)自己的需求選擇其中一種來刪除目錄。