删除HDFS上某个路径下特定类型的文件,比如class类型文件,比如txt类型文件
package com.zzm.day03;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
public class DeleteTwo {
public static void main(String[] args) throws Exception {
deleteS(new Path("/zzm"), "txt");
}
public static void deleteS(Path path, String type) throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
FileStatus[] listStatus = fs.listStatus(path);
for (FileStatus fst : listStatus) {
if (fst.getPath().toString().endsWith(type)) {
fs.delete(fst.getPath(), false);
}
}
}
}