package com.ghgj.cn.zy;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;
public class deleteClass {
// 删除特定类型的文件
public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop01:9000"), conf, "hadoop");
RemoteIterator<LocatedFileStatus> lf = fs.listFiles(new Path("/tt/aa"),true);
while(lf.hasNext()){
LocatedFileStatus next = lf.next();
Path p = next.getPath();
String name = next.getPath().getName();
if(name.endsWith(".txt")){
fs.delete(p, false);
}
}
}
}
删除特定文件(.txt)
最新推荐文章于 2023-12-07 10:56:49 发布